17 Abstract Factory

SOMETIMES, YOU WANT to provide for object creation while still retaining control of which class to instantiate. In such circumstances, you can apply the FACTORY METHOD pattern with a method that uses an outside factor to determine which class to instantiate. Sometimes, the factor that controls which object to instantiate can be thematic, running across several classes.

The intent of ABSTRACT FACTORY, or KIT, is to allow the creation of families of related or dependent objects.

A Classic Example: GUI Kits

GUI kits provide the classic example of the ABSTRACT FACTORY pattern. A GUI kit is an object that is an abstract factory, supplying GUI controls to a client that is building a user interface. Each GUI kit object ...

Get Design Patterns in Java™, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.