Part 2. Creational Patterns

All of the Creational patterns deal with ways to create instances of objects. This is important because your program should not depend on how objects are created and arranged. In Java, of course, the simplest way to create an instance of an object is by using the new operator:

fred = new Fred();    //instance of Fred class

However, doing this really amounts to hard coding, depending on how you create the object within your program. In many cases, the exact nature of the object that is created could vary with the needs of the program. Abstracting the creation process into a special "creator" class can make your program more flexible and general. The six Creational patterns follow:

  • Factory Method pattern. provides a simple ...

Get Java™ Design Patterns: A Tutorial 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.