Suresh Rohan's Blog

This blog is all about Java, J2EE,Spring, Angular, React JS, NoSQL, Microservices, DevOps, BigData, Tutorials, Tips, Best practice, Interview questions, Views, News, Articles, Techniques, Code Samples, Reference Application and much more

Monday, July 29, 2013

Prototype Pattern

Home

Prototype Pattern


Intent



  • specifying the kind of objects to create using a prototypical instance
  • creating new objects by copying this prototype


Implementation


The pattern uses abstract classes, as we will see below and only three types of classes making its implementation rather easy.














The classes participating to the Prototype Pattern are:

  • Client - creates a new object by asking a prototype to clone itself.
  • Prototype - declares an interface for cloning itself.
  • ConcretePrototype - implements the operation for cloning itself.


The process of cloning starts with an initialized and instantiated class. The Client asks for a new object of that type and sends the request to the Prototype class. A ConcretePrototype, depending of the type of object is needed, will handle the cloning through the Clone() method, making a new instance of itself.

Home

No comments:

Post a Comment