O'Reilly logo

Learning Java Functional Programming by Richard M Reese

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

Implementing the factory pattern

A common way of creating objects is using the new keyword with a constructor. However, if this is done repeatedly in many places in a program, the code used to create the object will need to be modified in each location should this process change. Using a factory method will simplify this process. The factory pattern is used to create different instances of different classes of the same base type.

The factory pattern is used to assist in the creation of objects. Where the use of the new keyword is not advisable, this technique should be used. This includes situations where context-dependent information is needed to create an instance and where we wish to have more control over the creation process.

In the former ...

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