Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 28 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
28
Dung lượng
1,16 MB
Nội dung
DESIGN PATTERNS EFA-EMS: Le Thi Thuy INTRODUCTION 1 Content I. What is a Design Pattern? II. Three categories of Design Pattern 2.1. List of Design Patterns 2.2. Design Pattern Space 2.3. Relation among Design Patterns III. Present common Design Patterns 3.1. Creational Patterns 3.2. Structural Patterns 3.3. Behavioral Pattern IV. Referent 2 I.What is a Design Pattern(1) Design patterns have their roots in the work of Christopher Alexander (a civil engineer who wrote about his experience in solving design issues as they related to buildings &towns) Software professionals began to incorporate Alexander's principles into the creation of early design pattern documentation as a guide to novice developers. 3 I. What is a Design Pattern(2) "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice” – Chirstopher Alexander “Description of communicating objects and classes that are customized to solve a general design problem in a particular context” - Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. Each pattern focuses in a particular object-oriented design problem or issue. 4 II. Three categories of Design Pattern Creational patterns: are ones that create objects for you, rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case. Structural patterns: help you compose groups of objects into larger structures, such as complex user interfaces or accounting data. Behavioral patterns: help you define the communication between objects in your system and how the flow is controlled in a complex program. 5 2.1. List of Design Patterns Creational Patterns • Abstract Factory • Builder • Factory Method • Prototype • Singleton Structural Patterns • Adapter • Bridge • Composite • Decorator • Facade • Flyweight • Proxy Behavioral Patterns – Chain of Responsibility – Command – Interpreter – Iterator – Mediator – Memento – Observer – State – Strategy – Template Method – Visitor 6 Purpose Creational Structural Behavioral Scope Class Factory Method Adapter (class) Interpreter Template Method Object Abstract Factory Builder Prototype Singleton Adapter (object) Bridge Composite Decorator Facade Flyweight Proxy Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor Defer object creation to another class Defer object creation to another object Describe algorithms and flow control Describe ways to assemble objects 2.2.Design Pattern Space 7 2.3. Relations among Design Patterns Builder Proxy saving state of iteration c r e a t i n g c o m p o s i t e s Memento Adapter Bridge Command Iterator A v o i d i n g h y s t e r e s i s Composite Decorator Enumerating children adding responsibilities to objects composed using sharing composites Flyweight defining grammar Interpreter Visitor a d d i n g o p e r a t i o n s d e f i n i n g t r a v e r s a l s d e f i n i n g t h e c h a i n Chain of Responsibility s h a r i n g s t r a t e g i e s changing skin versus guts Strategy a d d i n g o p e r a t i o n s State sharing strategies s h a r i n g t e r m i n a l s y m b o l s Mediator Observer co m p l e x d e p e n d e n c y m a n a g e m e n t Template Method defining algorithm´s steps Prototype Abstract Factory Singleton Facade Factory Method i m p l e m e n t u s i n g single instance single instance c o n f i g u r e f a c t o r y d y n a m i c a l l y often uses 8 III. Present common Design Patterns Creational Patterns • Abstract Factory • Builder • Factory Method • Singleton Structural Patterns • Adapter • Decorator Behavioral Patterns – Command – Observer – Strategy 9 3.1. Creational: Abstract Factory (1) > Intent: Packing a group of classes that have a role as a Factory in application. This is the class used to create objects. The factory of this class has common programming interface is inherited from parent class pure virtual (Virtual manufacturing). > Applicability • A system should be independent of how its products are created, composed, and represented. • A system should be configured with one of multiple families of products. • A family of related product objects is designed to be used together, and you need to enforce this constraint. • You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations. 10 . professionals began to incorporate Alexander's principles into the creation of early design pattern documentation as a guide to novice developers. 3 I. What is a Design Pattern(2) "Each pattern