Designing with Extensibility in Mind
Adding new features to a class might be as simple as extending an existing class, adding a few new methods, and modifying the behavior of others. It is not necessary to rewrite everything. This is where inheritance comes into play. If you have just written a Person
class, you must consider the fact that you might later want to write an Employee
class or a Vendor
class. Thus, having Employee
inherit from Person
might be the best strategy; in this case, the Person
class is said to be extensible. You do not want to design Person
so that it contains behavior that prevents it from being extended by classes such as Employee
or Vendor
(assuming that in your design, you really intend for other classes to extend
Get The Object-Oriented Thought Process, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.