O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required