1 / 18

Object-Oriented Design

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

rune
Download Presentation

Object-Oriented Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object-Oriented Design Design Patterns

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

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

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

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

  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. Composite: Application Part PartType GetType() int GetIdentifier() int GetTime() float GetQuality() int GetNumberOfRejections() SetRejectStatus(bool) bool GetRejectStatus() sub-parts * CompoundPart AddPart(Part) int GetNumberOfParts() Part * Decompose()

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

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

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

  11. Composite:General Structure

  12. Observer • Behavioral pattern • When changed, Subject notifies Observers

  13. Observer: Structure

  14. Observer: Sequence Diagram

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

  16. Creational Patterns • Abstract Factory • Builder • Factory Method • Prototype • Singleton

  17. Structural Patterns • Adapter • Bridge • Composite • Decorator • Facade • Flyweight • Proxy

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

More Related