Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
Prototype design patterns
Prototype design patterns
Loading in …3
1 of 15

Prototype presentation



Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Prototype presentation

  1. 1. Design Pattern Prototype Author: Vladislav Akulich QA automation Coherent Solutions Minsk 2014 1
  2. 2. Overview Prototype is a creational pattern. This pattern encapsulate the knowledge about which classes a system users, but they hide the details of how the instances of these classes are created and put together. 2
  3. 3. Intent Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype. 3
  4. 4. Applicability 4 • When the classes to instance are specified at run-time, for example, by dynamic loading • To avoid building a class hierarchy of factories that parallels the class hierarchy of products • When instance of a class can have one of only a few different combinations of state.
  5. 5. UML Diagram 5
  6. 6. Participant • Prototype –Declares an interface for cloning itself • Concrete Prototype –Implements an operation for cloning itself • Client –Creates a new object by asking a prototype to clone itself 6
  7. 7. Consequences • Adding and removing products at run-time • Specifying new objects by varying values • Specifying new objects by varying structure • Reduced subclassing • Configuring an application with classes dynamically 7
  8. 8. Copy options • Deep Copy (implementation in user code), but in some languages exist functions which do it • Simple object clone (standard function MemberwiseClone()) 8
  9. 9. Simple Copy • C# • Ruby 9
  10. 10. Deep Copy C# Ruby 10
  11. 11. Related Patterns Prototype and Abstract Factory are competing patterns. They can also be used together, however. An Abstract Factory might store a set prototypes from which to clone and return product objects. Designs that make heavy use of the Composite and Decorator patterns often can benefit from Prototype as well. 11
  12. 12. Code example Simple projects on: • C# • Ruby 12
  13. 13. Useful books • C# 3.0 Design Patterns • Gang of Four Design Patterns 4.0 • Code Complete Second Edition By Steve Mcconnell 13
  14. 14. Useful links • Ruby Best Practices: issue-25-creational-design-patterns.html • Prototype design pattern C++ example: pattern-c-example.html • Wikipedia: %82%D0%BE%D1%82%D0%B8%D0%BF_(%D1%88%D0%B0 %D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0 %BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE% D0%B2%D0%B0%D0%BD%D0%B8%D1%8F) 14
  15. 15. Thanks Vladislav Akulich ISsoft QA Engineer ISsoft Solutions