#567 – Wider vs. Narrower Types

In a object-oriented programming language like C#, due to inheritance, we often end up with a hierarchy of types.

Types lower down in the diagram above are known as derived classes and the class above them, which they inherit from, is known as their base class.  For example, Working is a derived class with respect to Dog, which is its base class.  Notice that a class can be both a derived class and a base class for another class.  (E.g. Working serves as a base class for Boxer).

We also refer to types higher up in the class hierarchy as wider and types further down as narrower.  The Dog class is wider than the Terrier class in the sense that there are more dogs than there are Terriers.  You can also think of the narrower classes as being more specialized–Terrier is a specific type of Dog.

Advertisement