page_title: Prototype pattern
section_title: UML class and sequence diagram
hierarchical_section_title: Prototype pattern / Structure / UML class and sequence diagram
caption_attribution_description: English: A sample class and sequence diagram for the Prototype design pattern.
context_page_description: The prototype pattern is a creational design pattern in software development. It is used 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 factory method pattern does.
  avoid the inherent cost of creating a new object in the standard way 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.
context_section_description: In the above UML class diagram, 
  the Client class that requires a Product object doesn't instantiate the Product1 class directly.
  Instead, the Client refers to the Prototype interface for cloning an object.
  The Product1 class implements the Prototype interface by creating a copy of itself.
  
  The UML sequence diagram shows the run-time interactions: 
  The Client object calls clone() on a prototype:Product1 object, which creates and returns a copy of itself (a product:Product1 object).
caption: A sample UML class and sequence diagram for the Prototype design pattern.
exif: {}