Chapter 14. Interfaces
In the previous chapter, we discussed inheritance as a way of abstracting common attributes of types into base types. Inheritance is a good way of expressing the essential nature of a type; for example, an Employee is a Person and a Manager is an Employee. But because types can only have a single base class, inheritance cannot be used to express general capabilities of types. For example, many types are “comparable,” which is the property of having values that can be “less than” or “greater than” other values. (For example, both numbers and dates are comparable types.) Comparable types have many useful attributes, not the least of which is that they can be sorted into an order.
However, inheritance is usually not sufficient ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access