SlideShare a Scribd company logo
1 of 58
Module 4:  UML In Action - Design Patterns
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Books ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],The manner in which a collection of interacting objects collaborate to accomplish a specific task or provide some specific functionality.
Architecture vs. Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],Architecture Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],Why Design Patterns?
4 Essential Elements of Design Patterns ,[object Object],[object Object],[object Object],[object Object]
How to Describe Design Patterns  more fully This is critical because the information has to be conveyed to peer  developers in order for them to be able to evaluate, select and utilize patterns. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Organizing Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Design Patterns Space Abstract Factory Builder Prototype Singleton Adapter Bridge Composite Decorator Façade Flyweight Proxy Chain of  Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor Factory Method Adapter Interpreter Template Creational Structural Behavioral Object Class Scope Purpose
Some Design Patterns Pattern Name Role Adapter Convert the interface of one class into another interface clients expect. Adapter allows classes to work together that otherwise can’t because of incompatible interfaces. Proxy Provide a surrogate or placeholder for another object. Mediator Define an object that encapsulates how  a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly and let one vary its interaction independently Observer Define a one-to-many dependency between objects so that when one object changes state, all its dependents will be notified and updated automatically. Template Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.
Structural Patterns ,[object Object],[object Object],[object Object],[object Object]
Structural Patterns - Composite ,[object Object],Composite: Applicability ,[object Object],[object Object],[object Object],Intent
Structural Patterns – Composite  Class Diagram Client Component operation() getChild( i:int ) Leaf operation() Composite operation() add( c:Component ) remove( c:Component ) getChild( i:int ) operation() { for all g in children g.operation() } *
Structural Patterns - Composite Object Diagram top : Composite top : Composite a : Leaf b : Leaf c : Leaf d : Leaf e : Leaf
Output  using  System; using  System.Collections; namespace  DoFactory.GangOfFour.Composite.Structural {    // MainApp test application     class  MainApp   {      static   void  Main()     {        // Create a tree structure        Composite root =  new  Composite("root");       root.Add( new  Leaf("Leaf A"));       root.Add( new  Leaf("Leaf B"));       Composite comp =  new  Composite("Composite X");       comp.Add( new  Leaf("Leaf XA"));       comp.Add( new  Leaf("Leaf XB"));       root.Add(comp);       root.Add( new  Leaf("Leaf C"));        // Add and remove a leaf        Leaf leaf =  new  Leaf("Leaf D");       root.Add(leaf);       root.Remove(leaf);        // Recursively display tree        root.Display(1);        // Wait for user        Console.Read();     }   } // "Component"     abstract   class  Component   { protected   string  name;      // Constructor       public  Component( string  name)     { this .name = name;}      public   abstract   void  Add(Component c);      public   abstract   void  Remove(Component c);      public   abstract   void  Display( int  depth);   }    // "Composite"     class  Composite : Component   { private  ArrayList children =  new  ArrayList();      // Constructor       public  Composite( string  name) :  base (name) {  }      public   override   void  Add(Component component)     {children.Add(component);}      public   override   void  Remove(Component component)     {children.Remove(component);}      public   override   void  Display( int  depth)     {Console.WriteLine( new  String('-', depth) + name);        // Recursively display child nodes         foreach  (Component component  in  children)       {component.Display(depth + 2);}     }   }   // "Leaf"     class  Leaf : Component   { // Constructor       public  Leaf( string  name) :  base (name) {  }      public   override   void  Add(Component c)     {Console.WriteLine("Cannot add to a leaf");}      public   override   void  Remove(Component c)     {Console.WriteLine("Cannot remove from a leaf");}      public   override   void  Display( int  depth)     {Console.WriteLine( new  String('-', depth) + name);}   } } http://www.dofactory.com/Patterns/PatternComposite.aspx -root ---Leaf A ---Leaf B ---Composite X -----Leaf XA -----Leaf XB ---Leaf C
Structural Patterns – Composite   ,[object Object],[object Object],[object Object],[object Object],Leaf ,[object Object],[object Object],Composite ,[object Object],[object Object],[object Object],Client ,[object Object],Component Participants
Structural Patterns – Composite   ,[object Object],[object Object],[object Object],Collaborations
Structural Patterns - Adapter ,[object Object],Applicability ,[object Object],[object Object],Intent
Structural Patterns - Adapter Client Adapter +request() Adaptee +specialOperation() Target +request() adaptee.specificOperation() Class Diagram
Structural Patterns - Adapter   ,[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],Collaborations
Structural Patterns -  Façade ,[object Object],Applicability ,[object Object],[object Object],[object Object],Intent
Structural Patterns -  Façade Class Diagram subsystem Facade
Structural Patterns -  Façade ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],[object Object],[object Object],[object Object],Collaborations
Structural Patterns -  Proxy ,[object Object],Applicability ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Intent
Structural Patterns -  Proxy Class Diagram Client <<abstract>> Subject request() ... RealSubject request() ... Proxy request() ... request() { ... realSubject.request() ... }
Structural Patterns -  Proxy Object Diagram aClient: aProxy : Proxy subject : RealSubject
Structural Patterns -  Proxy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],Collaborations
Behavioral Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object]
Behavioral Patterns - Observer ,[object Object],Intent ,[object Object],[object Object],[object Object],Applicability
Behavioral Patterns - Observer   Class Diagram subject observers * update() ConcreteObserver attach( observer ) detach( observer ) notify() Subject for all o in observers o.update() getState() subjectState ConcreteSubject update() <<interface>> Observer observerState := subject.getState()
Behavioral Patterns - Observer   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],[object Object],Collaborations
Behavioral Patterns - Observer   Sequence Diagram subject : ConcreteSubject observer1 : ConcreteObserver observer2  : ConcreteObserver attach( observer1 ) attach( observer2 ) update() getState() update() getState() notify()
Behavioral Patterns -  Strategy Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object]
Behavioral Patterns -  Strategy Pattern
Behavioral Patterns -  Participants of Strategy ,[object Object],[object Object],[object Object]
Behavioral Patterns -  Sorting Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Behavioral Patterns -  Strategy Pattern SortedList SetSortStr(sortStr:SortStrategy) Sort() SortStrategy Sort(list:ArrayList) InsertionSort Sort(list:ArrayList) QuickSort Sort(list:ArrayList) MergeSort Sort(list:ArrayList) -sortStrategy Main Main() stdRec -list: ArrayList Sort() {sortStrategy.Sort(list)} How is –sortStrategy implemented? Main() {… stdRec.SetSortStr(sortStrInfo); stdRec.Sort()} How is stdRec implemented?
Behavioral Patterns  - Command ,[object Object],Intent ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Applicability
Behavioral Patterns  -  Command Class Diagram * Client Invoker action() Receiver execute() <<abstract>> Command execute() state ConcreteCommand receiver.action()
Behavioral Patterns - Command ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],[object Object],[object Object],[object Object],Collaborations
Behavioral Patterns - Command aClient : Client aReceiver: anInvoker : Invoker aCommand : ConcreteCommand create( aReceiver ) store( aCommand ) action() execute() Sequence Diagram
Behavioral Patterns - State ,[object Object],Intent ,[object Object],[object Object],[object Object],[object Object],Applicability
Behavioral Patterns - State Class Diagram state request() Context state.handle(); handle() <<abstract>> State handle() ConcreteStateA handle() ConcreteStateB
Behavioral Patterns - State ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],[object Object],[object Object],[object Object],Collaborations
Behavioral Patterns - Visitor ,[object Object],Intent ,[object Object],[object Object],[object Object],Applicability
Behavioral Patterns - Visitor Class Diagram * Client visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) <<abstract>> Visitor visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) ConcreteVisitor1 visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) ConcreteVisitor2 ObjectStructure accept( v : Visitor ) <<abstract>> Element accept( v : Visitor ) operationA() ConcreteElementA accept( v : Visitor ) operationB() ConcreteElementB v.visitA( this ) v.visitB( this )
Behavioral Patterns - Visitor ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Participants ,[object Object],[object Object],[object Object],Collaborations
Behavioral Patterns - Visitor Sequence Diagram aStruct : ObjectStructure v : Visitor elemB : ConcreteElementB elemA : ConcreteElementA accept( v ) accept( v ) visitConcreteElementB( elemB ) operationB() visitConcreteElementA( elemA ) operationA()
How to Select & Use Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],How to Use How to Select  (> 20 in the book, and still growing … fast?, more on Internet )
Appendix: More on the Observer Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Subject Observer Observer Observer
Appendix: More on the Observer Pattern   The Model-View-Controller (MVC) ,[object Object],[object Object],[object Object],[object Object],Business Objects (the  Model  in MVC) Expert Interface Novice Interface Rationale for MVC:  Design for change and reuse   MVC and Observer Pattern ,[object Object],[object Object],[object Object]
Appendix: More on the Observer Pattern   java.util.Observable ,[object Object],[object Object],[object Object],[object Object],[object Object],Harry True/false ,[object Object],Subject Observer query setChanged() hasChanged()
Appendix: More on the Observer Pattern   Implementing & Checking an Observable ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Implementing an Observable public static void main (String args [ ] ) { Harry harry = new Harry (false); harry.updateMaritalStatus (true); if (harry.hasChanged() ) System.out.println (&quot;Time to call harry&quot;); } Checking an Observable
+ Good:  Any object can observe by calling hasChanged() -  Bad:  the observer must actively call hasChanged() ? What’s the alternative?  Automatic notification -> Observer pattern Appendix: More on the Observer Pattern   WHAT IF Observers query a Subject periodically? Good or Bad?
Appendix: More on the Observer Pattern   Implementing the Observer Pattern Harry Observer1 Observer2 addObserver (this) addObserver (observer2) Step 1: Observers register with Observable update(Observable o, Object arg) Harry notifyObservers(Object arg) Observer1 Observable (Harry) may also send himself a   notifyObservers()   msg - no params Step 2. Observable notifies Observers
Appendix: More on the Observer Pattern   java.util.Observable ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Points to Ponder ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlptguest8fdbdd
 
Design Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight PatternDesign Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight Patterneprafulla
 
UML and Software Modeling Tools.pptx
UML and Software Modeling Tools.pptxUML and Software Modeling Tools.pptx
UML and Software Modeling Tools.pptxNwabueze Obioma
 
Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web DevelopersDave Kelleher
 
Ch 5 O O Data Modeling Class
Ch 5  O O  Data Modeling ClassCh 5  O O  Data Modeling Class
Ch 5 O O Data Modeling Classguest8fdbdd
 
Uml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpUml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpSteve Nash
 
Ch 5 O O Data Modeling
Ch 5  O O  Data ModelingCh 5  O O  Data Modeling
Ch 5 O O Data Modelingguest8fdbdd
 
Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Designguest8fdbdd
 
Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Ricardo Quintero
 
Executable UML and SysML Workshop
Executable UML and SysML WorkshopExecutable UML and SysML Workshop
Executable UML and SysML WorkshopEd Seidewitz
 
Structural patterns
Structural patternsStructural patterns
Structural patternsHimanshu
 
Intro to UML 2
Intro to UML 2Intro to UML 2
Intro to UML 2rchakra
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UMLartgreen
 

What's hot (20)

UML Diagrams
UML DiagramsUML Diagrams
UML Diagrams
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlpt
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
 
Design Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight PatternDesign Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight Pattern
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
UML and Software Modeling Tools.pptx
UML and Software Modeling Tools.pptxUML and Software Modeling Tools.pptx
UML and Software Modeling Tools.pptx
 
Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web Developers
 
Ch 5 O O Data Modeling Class
Ch 5  O O  Data Modeling ClassCh 5  O O  Data Modeling Class
Ch 5 O O Data Modeling Class
 
Uml(unified modeling language) Homework Help
Uml(unified modeling language) Homework HelpUml(unified modeling language) Homework Help
Uml(unified modeling language) Homework Help
 
Ch 5 O O Data Modeling
Ch 5  O O  Data ModelingCh 5  O O  Data Modeling
Ch 5 O O Data Modeling
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Design
 
Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1Uml Omg Fundamental Certification 1
Uml Omg Fundamental Certification 1
 
Executable UML and SysML Workshop
Executable UML and SysML WorkshopExecutable UML and SysML Workshop
Executable UML and SysML Workshop
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 
Intro to UML 2
Intro to UML 2Intro to UML 2
Intro to UML 2
 
Uml introduciton
Uml introducitonUml introduciton
Uml introduciton
 
Lecture-03 Introduction to UML
Lecture-03 Introduction to UMLLecture-03 Introduction to UML
Lecture-03 Introduction to UML
 

Viewers also liked

Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)John Ortiz
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. ObserverFrancesco Ierna
 
Design patterns
Design patternsDesign patterns
Design patternsISsoft
 
Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionLearningTech
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton patternbabak danyal
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer patternJyaasa Technologies
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Augmelbournepatterns
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer patternpixelblend
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa TouchEliah Nikans
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfoliojobbo1
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer PatternMudasir Qazi
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSara Torkey
 
Observer Pattern
Observer PatternObserver Pattern
Observer PatternAkshat Vig
 

Viewers also liked (20)

Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. Observer
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expression
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer pattern
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Aug
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfolio
 
Design patterns - Observer Pattern
Design patterns - Observer PatternDesign patterns - Observer Pattern
Design patterns - Observer Pattern
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Observer Pattern
Observer PatternObserver Pattern
Observer Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 

Similar to M04 Design Patterns

Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural ModelingAMITJain879
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - AdapterManoj Kumar
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptTemesgenAzezew
 

Similar to M04 Design Patterns (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Sda 9
Sda   9Sda   9
Sda 9
 
uml2-1214558329929112-8.ppt
uml2-1214558329929112-8.pptuml2-1214558329929112-8.ppt
uml2-1214558329929112-8.ppt
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural Modeling
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
 

More from Dang Tuan

Javascript for php developer
Javascript for php developerJavascript for php developer
Javascript for php developerDang Tuan
 
Power your web skills
Power your web skillsPower your web skills
Power your web skillsDang Tuan
 
Ube Databases
Ube DatabasesUbe Databases
Ube DatabasesDang Tuan
 
Session02 Part Ii
Session02 Part IiSession02 Part Ii
Session02 Part IiDang Tuan
 
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UMLPHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UMLDang Tuan
 
M02 Uml Overview
M02 Uml OverviewM02 Uml Overview
M02 Uml OverviewDang Tuan
 
UML for OOAD
UML for OOADUML for OOAD
UML for OOADDang Tuan
 
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling IntroductionDang Tuan
 
Introduction to Modeling Java and UML
Introduction to Modeling Java and UMLIntroduction to Modeling Java and UML
Introduction to Modeling Java and UMLDang Tuan
 
Information Systems Analysis and Design Overview of OOAD, UML, and RUP
 Information Systems Analysis and Design Overview of OOAD, UML, and RUP Information Systems Analysis and Design Overview of OOAD, UML, and RUP
Information Systems Analysis and Design Overview of OOAD, UML, and RUPDang Tuan
 
Ooad Overview
Ooad OverviewOoad Overview
Ooad OverviewDang Tuan
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsDang Tuan
 
M05 Metamodel
M05 MetamodelM05 Metamodel
M05 MetamodelDang Tuan
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 StructuraldiagramsDang Tuan
 

More from Dang Tuan (20)

Javascript for php developer
Javascript for php developerJavascript for php developer
Javascript for php developer
 
Power your web skills
Power your web skillsPower your web skills
Power your web skills
 
Ube Databases
Ube DatabasesUbe Databases
Ube Databases
 
Chapter1
Chapter1Chapter1
Chapter1
 
Chapter9
Chapter9Chapter9
Chapter9
 
Chapter3
Chapter3Chapter3
Chapter3
 
Chapter7
Chapter7Chapter7
Chapter7
 
Chapter5
Chapter5Chapter5
Chapter5
 
Session02 Part Ii
Session02 Part IiSession02 Part Ii
Session02 Part Ii
 
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UMLPHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
 
Ooad Uml
Ooad UmlOoad Uml
Ooad Uml
 
M02 Uml Overview
M02 Uml OverviewM02 Uml Overview
M02 Uml Overview
 
UML for OOAD
UML for OOADUML for OOAD
UML for OOAD
 
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
 
Introduction to Modeling Java and UML
Introduction to Modeling Java and UMLIntroduction to Modeling Java and UML
Introduction to Modeling Java and UML
 
Information Systems Analysis and Design Overview of OOAD, UML, and RUP
 Information Systems Analysis and Design Overview of OOAD, UML, and RUP Information Systems Analysis and Design Overview of OOAD, UML, and RUP
Information Systems Analysis and Design Overview of OOAD, UML, and RUP
 
Ooad Overview
Ooad OverviewOoad Overview
Ooad Overview
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral Diagrams
 
M05 Metamodel
M05 MetamodelM05 Metamodel
M05 Metamodel
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 Structuraldiagrams
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

M04 Design Patterns

  • 1. Module 4: UML In Action - Design Patterns
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Design Patterns Space Abstract Factory Builder Prototype Singleton Adapter Bridge Composite Decorator Façade Flyweight Proxy Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor Factory Method Adapter Interpreter Template Creational Structural Behavioral Object Class Scope Purpose
  • 10. Some Design Patterns Pattern Name Role Adapter Convert the interface of one class into another interface clients expect. Adapter allows classes to work together that otherwise can’t because of incompatible interfaces. Proxy Provide a surrogate or placeholder for another object. Mediator Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly and let one vary its interaction independently Observer Define a one-to-many dependency between objects so that when one object changes state, all its dependents will be notified and updated automatically. Template Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.
  • 11.
  • 12.
  • 13. Structural Patterns – Composite Class Diagram Client Component operation() getChild( i:int ) Leaf operation() Composite operation() add( c:Component ) remove( c:Component ) getChild( i:int ) operation() { for all g in children g.operation() } *
  • 14. Structural Patterns - Composite Object Diagram top : Composite top : Composite a : Leaf b : Leaf c : Leaf d : Leaf e : Leaf
  • 15. Output using System; using System.Collections; namespace DoFactory.GangOfFour.Composite.Structural {    // MainApp test application    class MainApp   {      static void Main()     {        // Create a tree structure       Composite root = new Composite(&quot;root&quot;);       root.Add( new Leaf(&quot;Leaf A&quot;));       root.Add( new Leaf(&quot;Leaf B&quot;));       Composite comp = new Composite(&quot;Composite X&quot;);       comp.Add( new Leaf(&quot;Leaf XA&quot;));       comp.Add( new Leaf(&quot;Leaf XB&quot;));       root.Add(comp);       root.Add( new Leaf(&quot;Leaf C&quot;));        // Add and remove a leaf       Leaf leaf = new Leaf(&quot;Leaf D&quot;);       root.Add(leaf);       root.Remove(leaf);        // Recursively display tree       root.Display(1);        // Wait for user       Console.Read();     }   } // &quot;Component&quot;    abstract class Component   { protected string name;      // Constructor      public Component( string name)     { this .name = name;}      public abstract void Add(Component c);      public abstract void Remove(Component c);      public abstract void Display( int depth);   }    // &quot;Composite&quot;    class Composite : Component   { private ArrayList children = new ArrayList();      // Constructor      public Composite( string name) : base (name) {  }      public override void Add(Component component)     {children.Add(component);}      public override void Remove(Component component)     {children.Remove(component);}      public override void Display( int depth)     {Console.WriteLine( new String('-', depth) + name);        // Recursively display child nodes        foreach (Component component in children)       {component.Display(depth + 2);}     }   }   // &quot;Leaf&quot;    class Leaf : Component   { // Constructor      public Leaf( string name) : base (name) {  }      public override void Add(Component c)     {Console.WriteLine(&quot;Cannot add to a leaf&quot;);}      public override void Remove(Component c)     {Console.WriteLine(&quot;Cannot remove from a leaf&quot;);}      public override void Display( int depth)     {Console.WriteLine( new String('-', depth) + name);}   } } http://www.dofactory.com/Patterns/PatternComposite.aspx -root ---Leaf A ---Leaf B ---Composite X -----Leaf XA -----Leaf XB ---Leaf C
  • 16.
  • 17.
  • 18.
  • 19. Structural Patterns - Adapter Client Adapter +request() Adaptee +specialOperation() Target +request() adaptee.specificOperation() Class Diagram
  • 20.
  • 21.
  • 22. Structural Patterns - Façade Class Diagram subsystem Facade
  • 23.
  • 24.
  • 25. Structural Patterns - Proxy Class Diagram Client <<abstract>> Subject request() ... RealSubject request() ... Proxy request() ... request() { ... realSubject.request() ... }
  • 26. Structural Patterns - Proxy Object Diagram aClient: aProxy : Proxy subject : RealSubject
  • 27.
  • 28.
  • 29.
  • 30. Behavioral Patterns - Observer Class Diagram subject observers * update() ConcreteObserver attach( observer ) detach( observer ) notify() Subject for all o in observers o.update() getState() subjectState ConcreteSubject update() <<interface>> Observer observerState := subject.getState()
  • 31.
  • 32. Behavioral Patterns - Observer Sequence Diagram subject : ConcreteSubject observer1 : ConcreteObserver observer2 : ConcreteObserver attach( observer1 ) attach( observer2 ) update() getState() update() getState() notify()
  • 33.
  • 34. Behavioral Patterns - Strategy Pattern
  • 35.
  • 36.
  • 37. Behavioral Patterns - Strategy Pattern SortedList SetSortStr(sortStr:SortStrategy) Sort() SortStrategy Sort(list:ArrayList) InsertionSort Sort(list:ArrayList) QuickSort Sort(list:ArrayList) MergeSort Sort(list:ArrayList) -sortStrategy Main Main() stdRec -list: ArrayList Sort() {sortStrategy.Sort(list)} How is –sortStrategy implemented? Main() {… stdRec.SetSortStr(sortStrInfo); stdRec.Sort()} How is stdRec implemented?
  • 38.
  • 39. Behavioral Patterns - Command Class Diagram * Client Invoker action() Receiver execute() <<abstract>> Command execute() state ConcreteCommand receiver.action()
  • 40.
  • 41. Behavioral Patterns - Command aClient : Client aReceiver: anInvoker : Invoker aCommand : ConcreteCommand create( aReceiver ) store( aCommand ) action() execute() Sequence Diagram
  • 42.
  • 43. Behavioral Patterns - State Class Diagram state request() Context state.handle(); handle() <<abstract>> State handle() ConcreteStateA handle() ConcreteStateB
  • 44.
  • 45.
  • 46. Behavioral Patterns - Visitor Class Diagram * Client visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) <<abstract>> Visitor visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) ConcreteVisitor1 visitA( element : ConcreteElementA ) visitB( element : ConcreteElementB ) ConcreteVisitor2 ObjectStructure accept( v : Visitor ) <<abstract>> Element accept( v : Visitor ) operationA() ConcreteElementA accept( v : Visitor ) operationB() ConcreteElementB v.visitA( this ) v.visitB( this )
  • 47.
  • 48. Behavioral Patterns - Visitor Sequence Diagram aStruct : ObjectStructure v : Visitor elemB : ConcreteElementB elemA : ConcreteElementA accept( v ) accept( v ) visitConcreteElementB( elemB ) operationB() visitConcreteElementA( elemA ) operationA()
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. + Good: Any object can observe by calling hasChanged() - Bad: the observer must actively call hasChanged() ? What’s the alternative? Automatic notification -> Observer pattern Appendix: More on the Observer Pattern WHAT IF Observers query a Subject periodically? Good or Bad?
  • 55. Appendix: More on the Observer Pattern Implementing the Observer Pattern Harry Observer1 Observer2 addObserver (this) addObserver (observer2) Step 1: Observers register with Observable update(Observable o, Object arg) Harry notifyObservers(Object arg) Observer1 Observable (Harry) may also send himself a notifyObservers() msg - no params Step 2. Observable notifies Observers
  • 56.
  • 57.
  • 58.