Recognizing Factory Method

You might think any method that creates and returns a new object is a “factory” method. In object-oriented programming, however, methods that return new objects are common, and not every such method is an instance of the FACTORY METHOD pattern.

CHALLENGE 16.1Name two commonly used Java methods that return a new object.

The fact that a method creates a new object does not in itself mean that it is an example of the FACTORY METHOD pattern. The FACTORY METHOD pattern requires that an operation that creates an object also isolates its client from knowing which class to instantiate. In FACTORY METHOD, you will find several classes that implement the same operation, returning the same, abstract type but internally instantiating ...

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.