Prototype Pattern

If you've worked with ISO9000 and the like, you know there is a Document Control Librarian. This person is responsible for handing out and maintaining "official" copies of documents as required by ISO. If you want to get access to a document, you go to the Librarian and request a copy.

The Librarian doesn't know very much at all about the documents he's handing out. Someone else created the document and gave it to him. He just knows a very few things:

From time to time, he's given updates to a document. Again, he doesn't know what the updates are or what they mean, he just knows that he now hands out copies of the new version.

You don't know who gave the original copy to the Librarian. It may have been an outside consultant, it could be another Engineer in your company, or it may have even been you. You don't know how that original copy was created in the first place. It may be a very complicated document requiring elaborate steps to create or it took many years to create.

You can't ask the librarian for a slightly different version of a document, he won't know what you're talking about. However, the copy you received might give you a way to modify itself, perhaps with some fill-in-the-blank pages.

Analogous Entities

Document Control Librarian=>PrototypeManager class
the documents =>the Prototypical classes
the photocopier =>the Clone() method(s) on all the prototype classes
document created elsewhere=>the construction of the prototype class is done by another class

The analogy breaks down

The highlights are:


Factory Pattern

In contrast, a Factory RWE might be McDonalds. If you need a hamburger, you go to the local McDonalds to get one. You don't go to the local bakery because they don't make hamburgers there. You somehow magically know that hamburgers are created at McDonalds.

McDonalds builds the hamburger on the spot. They don't, for example, have Ray Kroc's first hamburger, ask it to copy itself and give you the copy. And you, as the customer, don't have to know what's in the secret sauce (1000 Island dressing).

The people who work at McDonalds have some knowledge about constructing hamburgers but can only generate what's on the menu. You can tailor your hamburger on the spot, e.g. "Hold the pickles". But you have to know what you can and can't change about the hamburger, with a little help from the McDonald's staff and menu, e.g. you have to know what "Supersize" means, and you can't ask for Adovo sauce instead of secret sauce.

The people who work at McDonald's don't really create the hamburgers, they just assemble it according to instructions given to them from McDonald's HQ. The "hamburger creation knowledge" is not at the local McDonald's, just the ingredients and the instructions.

The analogous entities are:

McDonalds =>the Factory class
the hamburger =>the object instance
the staff =>the Factory method used to create the object instance
McDonald's HQ =>the actual class constructor(s)

The analogy breaks down:

The highlights are: