- Hands-On Network Programming with C# and .NET Core
- Sean Burns
- 237字
- 2021-06-24 16:05:29
The interface
With any type of abstract class or interface definition, their proper use can best be understood through two distinct lenses. The shape of the abstraction is made clear by the properties of the interface. This gives users a concrete idea of the proper context in which instances of the interface should be used. It should clearly convey the domain around which the abstraction should operate. Meanwhile, the scope of the abstraction is conveyed by the classes' method signatures. This is what tells users how the class operates over the domain, as defined by its shape or properties.
An interface of well-named methods should give clear boundaries to the limits of the usefulness of the class. If an interface is well defined, as with the WebRequest base class, its properties and method signatures should make it clear exactly when it should, and should not be used. What's more, if it should be used, well-named and well-scoped method signatures will tell users exactly how to use the method.
So, with that perspective in mind, let's take a look at what is in the base definition of the WebRequest class. This specification will tell us how it is meant to be used and how to extend or implement it for ourselves. And what better place to start than with the constructors?