18 Prototype

WHEN YOU DEVELOP a class, you ordinarily furnish it with constructors to let client applications instantiate it. In some circumstances, you may decide to isolate users of your class from directly calling a constructor. The construction-oriented patterns covered so far—BUILDER, FACTORY METHOD, and ABSTRACT FACTORY—all provide this isolation. These patterns establish methods that instantiate an appropriate class on a client’s behalf. The PROTOTYPE pattern also conceals object creation from clients but uses a different approach.

The intent of the PROTOTYPE pattern is to provide new objects by copying an example rather than by bringing forth new, uninitialized instances of a class.

Prototypes as Factories

Suppose that ...

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.