SlideShare une entreprise Scribd logo
1  sur  12
Prototype Pattern
● One of Creational Patterns
● Others: Singleton, Factory Method, Abstract
Factory, Builder
Purpose
To make dynamic creation easier by defining
classes whose objects can create
duplicates of themselves.
Motivation
Sometimes, it becomes necessary to copy
or clone an “already grown” object rather
than instantiating it and setting its values.
Applicability
- Use the Prototype pattern when you want to create an
object that is a copy of an existing object.
- When instances of a class can have one of only a few
different combinations of state.
Structure
Participants
Prototype declares an interface for cloning
itself.
ConcretePrototype implements an
operation for cloning itself.
Client creates a new object by asking a
prototype to clone itself.
Implementaion
Implementaion
Shallow vs Deep Copy
● A shallow copy duplicates only the top-level
elements of a class; this provides a faster copy, but
isn’t suitable for all needs.
● Deep copy operations replicate not only the top-level
attributes, but also the lower-level objects. This
typically takes longer than shallow copy operations,
and can be very costly for objects with an arbitrarily
complex structure.
Related Patterns
● Abstract Factory – Abstract Factories can
use the Prototype to create new objects
based on the current use of the Factory.
● Factory Method – Factory Methods can
use a Prototype to act as a template for
new objects.
Pros and Cons
Pros:
● Hides the complexities of making new instances from
the client.
● In certain circumstances, copy an object is more
efficient than creating a new object
● Using a Prototype design pattern hides concrete
product classes from the client
Cons:
● Classes can be difficult to deep clone
Questions?

Contenu connexe

Tendances

Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 

Tendances (20)

Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract Factory
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 

En vedette

Prototype presentation
Prototype presentationPrototype presentation
Prototype presentation
ISsoft
 

En vedette (10)

Prototype Pattern
Prototype PatternPrototype Pattern
Prototype Pattern
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Prototype presentation
Prototype presentationPrototype presentation
Prototype presentation
 
Design Patterns and Usage
Design Patterns and UsageDesign Patterns and Usage
Design Patterns and Usage
 
Builder pattern vs constructor
Builder pattern vs constructorBuilder pattern vs constructor
Builder pattern vs constructor
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 
John Mayer
John MayerJohn Mayer
John Mayer
 
Cruise celebrity eclipse algemene informatie
Cruise celebrity eclipse   algemene informatieCruise celebrity eclipse   algemene informatie
Cruise celebrity eclipse algemene informatie
 
PSYCHO VIDEO SLIDES
PSYCHO VIDEO SLIDESPSYCHO VIDEO SLIDES
PSYCHO VIDEO SLIDES
 
Crowd funding revised
Crowd funding revisedCrowd funding revised
Crowd funding revised
 

Similaire à Prototype_pattern

Design patterns
Design patternsDesign patterns
Design patterns
Alok Guha
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
P Heinonen
 

Similaire à Prototype_pattern (20)

Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Desing Patterns Summary - by Jim Fawcett
Desing Patterns Summary - by Jim FawcettDesing Patterns Summary - by Jim Fawcett
Desing Patterns Summary - by Jim Fawcett
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Object Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) javaObject Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) java
 
Sda 8
Sda   8Sda   8
Sda 8
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Creating and destroying objects
Creating and destroying objectsCreating and destroying objects
Creating and destroying objects
 
Ahieving Performance C#
Ahieving Performance C#Ahieving Performance C#
Ahieving Performance C#
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Effective java
Effective javaEffective java
Effective java
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Creational Patterns
Creational PatternsCreational Patterns
Creational Patterns
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
 
AngularJS
AngularJSAngularJS
AngularJS
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
 

Dernier

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Prototype_pattern

  • 1. Prototype Pattern ● One of Creational Patterns ● Others: Singleton, Factory Method, Abstract Factory, Builder
  • 2. Purpose To make dynamic creation easier by defining classes whose objects can create duplicates of themselves.
  • 3. Motivation Sometimes, it becomes necessary to copy or clone an “already grown” object rather than instantiating it and setting its values.
  • 4. Applicability - Use the Prototype pattern when you want to create an object that is a copy of an existing object. - When instances of a class can have one of only a few different combinations of state.
  • 6. Participants Prototype declares an interface for cloning itself. ConcretePrototype implements an operation for cloning itself. Client creates a new object by asking a prototype to clone itself.
  • 9. Shallow vs Deep Copy ● A shallow copy duplicates only the top-level elements of a class; this provides a faster copy, but isn’t suitable for all needs. ● Deep copy operations replicate not only the top-level attributes, but also the lower-level objects. This typically takes longer than shallow copy operations, and can be very costly for objects with an arbitrarily complex structure.
  • 10. Related Patterns ● Abstract Factory – Abstract Factories can use the Prototype to create new objects based on the current use of the Factory. ● Factory Method – Factory Methods can use a Prototype to act as a template for new objects.
  • 11. Pros and Cons Pros: ● Hides the complexities of making new instances from the client. ● In certain circumstances, copy an object is more efficient than creating a new object ● Using a Prototype design pattern hides concrete product classes from the client Cons: ● Classes can be difficult to deep clone