Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.

Similar presentations


Presentation on theme: "1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids."— Presentation transcript:

1 1 Design Patterns Object-Oriented Design

2 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids “reinventing the wheel” 4 Design Patterns, Gamma, Helm, Johnson, Vlissides (GoF) 4Architecture: Christopher Alexander

3 3 Elements of a Design Pattern 4name - simple, descriptive term 4intent - brief description of aim 4motivation - concrete example 4applicability - where is it useful? 4structure - “blueprint” diagram 4participants - each class in pattern

4 4 Elements of a Design Pattern (cont’d) 4collaborations - relationships among participants 4consequences - implications of use 4implementation - general implementation 4sample code - code for a particular application 4known uses - applications where used 4related patterns - to combine or substitute problem areas

5 5 Example Pattern: Composite 4Structural pattern 4Represent part-whole relationships in tree hierarchy 4Uniform treatment of individual objects

6 6 Composite: Application Piece PartType GetType() int GetIdentifier() int GetTime() float GetQuality() int GetNumberOfRejections() SetRejectStatus(bool) bool GetRejectStatus() CompoundPart AddPart(Part) int GetNumberOfParts() Part * Decompose() PartType GetType() int GetIdentifier() int GetTime() float GetQuality() int GetNumberOfRejections() SetRejectStatus(bool) bool GetRejectStatus() sub-parts *

7 7 Composite: Application Part PartType GetType() int GetIdentifier() int GetTime() float GetQuality() int GetNumberOfRejections() SetRejectStatus(bool) bool GetRejectStatus() CompoundPart AddPart(Part) int GetNumberOfParts() Part * Decompose() sub-parts *

8 8 Composite Pattern Example: Simulation Components SimComponent PartType GetType() int GetIdentifier() int GetTime() float GetQuality() int GetNumberOfRejections() SetRejectStatus(bool) bool GetRejectStatus() Composite all of ops()... AddPart(Part) int GetNumberOfParts() Part * Decompose() Piece PartType GetType()... all of the ops()... Inheritance Contains 1 or more Components in a variable called sub-pieces sub-pieces

9 9 Composite Pattern Example: A Graphic Graphic Draw() Add(Graphic) Remove(int) GetChild(int) Picture Draw() Add(Graphic) Remove(int) GetChild(int) Text Draw() Rectangle Draw() Line Draw() Inheritance Contains 1 or more Graphics in a variable called graphics graphics for all g in graphics g.Draw() Add/Remove Graphic to/from list of graphics

10 10 Composite Pattern Example: A Graphic MailBody Disp() Add(Attch) Remove(int) GetChild(int) Attachments Disp() Add(Attch) Remove(int) GetChild(int) Pic Disp() Image Disp() Text Disp() attchs for all m in attchs m.Disp() Alternatively: Display a list of attachments

11 11 Composite: General Structure

12 12 Observer 4Behavioral pattern 4When changed, Subject notifies Observers

13 13 Observer: Structure

14 14 Observer: Sequence Diagram

15 15 Observer: Application Unit AddPart(Part *) GetNumberFinalParts() Part * GetFinalPart() SetTypesRequired(PartType *, int num) AddUnitObserver(UnitObserver *) NotifyObservers() UnitObserver Update() Update(Unit *) ProductRemovalObserver Update(Unit *) Observer Update() // called when unit completes a part for all o in observers o.Update(this)

16 16 Creational Patterns 4Abstract Factory 4Builder 4Factory Method 4Prototype 4Singleton

17 17 Structural Patterns 4Adapter 4Bridge 4Composite 4Decorator 4Facade 4Flyweight 4Proxy

18 18 Behavioral Patterns 4Chain of Responsibility 4Command 4Interpreter 4Iterator 4Mediator 4Memento 4Observer 4State 4Strategy 4Template Method 4Visitor


Download ppt "1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids."

Similar presentations


Ads by Google