Reuse as an Alternative to Extension
When you shop around before you code, you have less code to maintain, you benefit from the wisdom of developers who have gone before you, and you can ensure that your own code dovetails with the class you are extending. Every class that you create will inherit from the Object class, and this is a natural place to start shopping for existing code. Figure 26.1 shows the Object class.
Figure 26.1. The Object class has methods that every OO developer should know how to use.
Earlier examples in this book have reused most of the behavior available in Object, including the clone(), equals(), and getClass() methods. ...
Get Design Patterns Java™ Workbook 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.