Prototype Pattern

The prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used to:

  • avoid subclasses of an object creator in the client application, like the abstract factory pattern does.
  • avoid the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) when it is prohibitively expensive for a given application.

To implement the pattern, declare an abstract base class that specifies a pure virtual clone method. Any class that needs a "polymorphic constructor" capability derives itself from the abstract base class, and implements the clone operation.

The client, instead of writing code that invokes the "new" operator on a hard-coded class name, calls the clone method on the prototype, calls a factory method with a parameter designating the particular concrete derived class desired, or invokes the clone method through some mechanism provided by another design pattern.

Read more about Prototype Pattern:  Example, Rules of Thumb

Famous quotes containing the words prototype and/or pattern:

    The Ancient Mariner seizes the guest at the wedding feast and will not let go until he has told all his story: the prototype of the bore.
    Mason Cooley (b. 1927)

    His talent was as natural as the pattern that was made by the dust on a butterfly’s wings. At one time he understood it no more than the butterfly did and he did not know when it was brushed or marred. Later he became conscious of his damaged wings and of their construction and he learned to think and could not fly any more because the love of flight was gone and he could only remember when it had been effortless.
    Ernest Hemingway (1899–1961)