PROTOTYPE PATTERN
Devashish Mahbubani Y13UC084
Kushal Mishra
Y13UC151
Shubham Gupta
Y13UC276
DEFINITION
Prototype pattern refers to creating duplicate object
while keeping performance in mind. This type of
design pattern comes under creational pattern as
this pattern provides one of the best ways to create
an object.
This pattern involves implementing a prototype
interface which tells to create a clone of the current
object. This pattern is used when creation of object
directly is costly.
EXAMPLE
An object is to be created after a costly
database operation. We can cache the
object, returns its clone on next request
and update the database as and when
needed thus reducing database calls.
CLASS DIAGRAM
When to use Prototype Pattern:
[Link] Prototype Pattern when creating an instance of a given
class is either expensive or complicated (or) when a system
must create new objects of many types in a complex class
hierarchy.
[Link] there are many subclasses that differ only in the kind
of objects, A system needs independent of how its objects are
created, composed, and represented.
Disadvantages:
Drawback to using the Prototype is that making a copy of an
object can
sometimes be complicated.