0% found this document useful (0 votes)
5 views15 pages

Understanding the Prototype Pattern

The document discusses the Prototype Pattern, a creational design pattern that allows for object creation by copying a prototypical instance. It outlines when to use the pattern, its advantages such as decoupling product creation from system behavior, and its drawbacks including complications with the cloning method. The lecture also includes UML diagrams and example code to illustrate the concept.

Uploaded by

abidhasanjim1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

Understanding the Prototype Pattern

The document discusses the Prototype Pattern, a creational design pattern that allows for object creation by copying a prototypical instance. It outlines when to use the pattern, its advantages such as decoupling product creation from system behavior, and its drawbacks including complications with the cloning method. The lecture also includes UML diagrams and example code to illustrate the concept.

Uploaded by

abidhasanjim1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lecture 8

Kazi Rifat Ahmed


Lecturer
Department of Software Engineering
Daffodil International University
Prototype Pattern
● What is Prototype Pattern
● When to use
● Drawbacks of prototype pattern

Outline ●

Usage of prototype pattern
Where it can be implemented
● Real life problem and its
necessary
Prototype Pattern

►A creational pattern
► Specify the kinds of objects to create using a
prototypical instance, and create new objects by
copying this prototype
Problem
Prototype solution
Prototype Pattern UML
Participants:
• Prototype
o declares an interface
for cloning itself.
• ConcretePrototype
o implements an
operation for cloning
itself.
• Client
o creates a new object
by asking a prototype
to clone itself.
Example
Animal farm
Prototype Pattern Example code
Prototype Pattern Example code
Prototype Pattern Example code
Prototype Pattern
When to Use
► When product creation should be decoupled
from system behavior
► When to avoid subclasses of an object
creator in the client application
► When creating an instance of a class is
time-consuming or complex in some way.
Consequences of Prototype Pattern
► Hides the concrete product classes from
the client
► Adding/removing of prototypes at run-time
► Allows specifying new objects by varying
values or structure
► Reducing the need for sub-classing
Drawbacks of Prototype Pattern
► It is built on the method .clone(), which
could be complicated sometimes in terms of
shallow copy and deep copy. Moreover,
classes that have circular references to
other classes cannot really be cloned.
Thank You

You might also like