Prototype

Prototype pattern suggests copying or cloning the existing object and customizing it if needed rather than creating a new object. Choose this pattern when a system should be independent of its products creation, compose, and representation:

We can create a copy of PublicProfile (limited information) or FullProfile at runtime. Those two classes share a few combination of states, so it is good that we design as a prototype.

Let's take a look at its benefits:

  • Adding and removing products at runtime
  • Specifying new objects by varying values and structures
  • Reduced subclasses
  • Dynamic class configuration to an application

The impact is, each subclass must implement clone operation, and it is not possible to clone circular reference classes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset