Prototype presentation
-
Upload
issoft -
Category
Technology
-
view
282 -
download
4
Transcript of Prototype presentation
![Page 1: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/1.jpg)
1
Design Pattern PrototypeAuthor:
Vladislav AkulichQA automation
Coherent Solutions
Minsk 2014
![Page 2: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/2.jpg)
OverviewPrototype 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
![Page 3: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/3.jpg)
Intent
Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype.
3
![Page 4: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/4.jpg)
4
Applicability• 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.
![Page 5: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/5.jpg)
5
UML Diagram
![Page 6: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/6.jpg)
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
![Page 7: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/7.jpg)
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
![Page 8: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/8.jpg)
8
Copy options
• Deep Copy (implementation in user code), but in some languages exist functions which do it
• Simple object clone (standard function MemberwiseClone())
![Page 9: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/9.jpg)
Simple Copy • C#
• Ruby
9
![Page 10: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/10.jpg)
Deep CopyC# Ruby
10
![Page 11: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/11.jpg)
11
Related PatternsPrototype 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.
![Page 12: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/12.jpg)
12
Code example
Simple projects on:• C#• Ruby
![Page 13: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/13.jpg)
Useful books• C# 3.0 Design Patterns• Gang of Four Design Patterns 4.0• Code Complete Second Edition By Steve
Mcconnell
13
![Page 14: Prototype presentation](https://reader036.fdocuments.us/reader036/viewer/2022082605/55497d8cb4c90583678b45ee/html5/thumbnails/14.jpg)
Useful links• Ruby Best Practices:
http://blog.rubybestpractices.com/posts/gregory/059-issue-25-creational-design-patterns.html
• Prototype design pattern C++ example: http://www.ccplusplus.com/2012/01/prototype-design-pattern-c-example.html
• Wikipedia: http://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%BE%D1%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