SlideShare uma empresa Scribd logo
1 de 37
Prophecy of Design Patterns




Sep 11th,12th & 13th 2012

                                                    By Pradeep Kothiyal
 What are design patterns?
   Design Patterns are:
    Recurring solutions to software design problems you find
   again and again in real-world application development.
    A general reusable solution to a commonly occurring problem
   in software design.     - wiki
    It is a description or template for how to solve a problem that
   can be used in many different situations.
    Are about design and interaction of objects, as well as
   providing a communication platform concerning elegant,
   reusable solutions to commonly encountered programming
   challenges.
    GoF Patterns are considered the foundation of all design
   patterns.
 What are design patterns?
   Design Patterns are:
    NOT a finished design that can be transformed directly in
   code.
    Object-oriented design patterns shows relationships and
   interactions between classes or objects without specifying the
   final application classes or objects that are involved.
    Design patterns reside in the domain of modules and
   interconnections. At a higher level there are Architectural
   patterns[larger in scope], usually describing an overall pattern
   followed by an entire system.
    NOT ALL software patterns are design patterns.
       Ex: Algorithms solve computational problems rather than
       software design problems.
 GoF’s contributions in design pattern
     Gang of Four was a team of four members: Erich Gamma,
    Richard Helm, Ralph Johnson and John Vlissides.




                (L-R) Ralph, Erich, Richard and John
 GoF’s contributions in design pattern
     Profiles:
         Erich Gamma: Technical Director at Software Technology
        Center of OTI at Zurich. Currently working on the IBM
        Rational Jazz project
         Richard Helm: With Boston Consulting Group(BCG) in
        Sydney, OZ.
         Ralph Johnson: Working on the PatternStoriesWiki and
        promoting the OnLineComputerMuseum. Research Associate
        Professor in the Department of Computer Science at the
        University of Illinois at Urbana-Champaign
         John Vlissides: Was researcher at IBM's T.J. Watson
        Research Center.
    All 23 patterns has been designed by GoF.
    There are more then 300 design patterns in developer
    community, which are derived from these 23 patterns.
 Three broad visions:
     Creational Patterns:
            are design patterns that deals with Object Creation
    Mechanism, trying to create objects in a manner suitable to the
    situation. Ex: Abstract Factory, Factory Method etc.
     Structural Patterns:
             ease the design by identifying a simple way to realize
    relationship between entities. Ex: Façade, Adapter, Proxy etc.
     Behavioral Patterns:
             Identify common communication patterns between
    objects and realize these patterns, thus increases flexibility in
    carrying out this communications. Ex: Observer, Iterator,
    Command etc.
 Commonly used patterns:

  S No   Category                 Pattern   Usage
    1    Creational    Factory Method*
    2                  Abstract Factory
    3                  Singleton
    4     Structural   Adapter
    5                  Composite
    6                  Façade*
    7    Behavioral    Command
    8                  Iterator
    9                  Observer*
   10                  Strategy

                                               *sample examples
 Factory Method:                             [Creational Patterns]
    Definition:
            Define an interface for creating an object, but let
    subclasses decide which class to instantiate.
            Lets a class defer instantiation to subclasses.
    Participants:
    Product (Page) : defines the interface of objects the factory
    method creates.
    ConcreteProduct (SkillsPage, EducationPage, ExperiencePage):
    implements the Product interface
    Creator (Document) : declares the factory method, which
    returns an object of type Product.
    Creator may also define a default implementation of the
    factory method that returns a default ConcreteProduct object.
    may call the factory method to create a Product object.
    ConcreteCreator (Report, Resume): overrides the factory
    method to return an instance of a ConcreteProduct.
 Factory Method:      [Creational Patterns]
   UML Notification:




                              Code Example
 Abstract Factory:                        [Creational Patterns]
   Definition:
          Provide an interface for creating families of related or
   dependent objects without specifying their concrete classes.
   Participants:
   AbstractFactory (ContinentFactory): declares an interface for
   operations that create abstract products.
   ConcreteFactory (AfricaFactory, AmericaFactory): implements
   the operations to create concrete product objects.
   AbstractProduct (Herbivore, Carnivore): declares an interface
   for a type of product object.
   Product (Wildebeest, Lion, Bison, Wolf): defines a product
   object to be created by the corresponding concrete factory.
   implements the AbstractProduct interface.
   Client (AnimalWorld): uses interfaces declared by
   AbstractFactory and AbstractProduct classes.
 Abstract Factory:    [Creational Patterns]
   UML Notification:
 Singleton:                               [Creational Patterns]
   Definition:
            Ensure a class has only one instance and provide a
   global point of access to it.
   Participants:
   Singleton (LoadBalancer): defines an Instance operation that
   lets clients access its unique instance. Instance is a class
   operation.
   responsible for creating and maintaining its own unique
   instance.
   UML Notification:
 Adapter:                                  [Structural Patterns]
   Definition:
            Convert the interface of a class into another interface
   clients expect.
          Lets classes work together that couldn't otherwise
   because of incompatible interfaces.
   Participants:
   Target (ChemicalCompound): defines the domain-specific
   interface that Client uses.
   Adapter (Compound): adapts the interface Adaptee to the
   Target interface.
   Adaptee (ChemicalDatabank): defines an existing interface that
   needs adapting.
   Client (AdapterApp): collaborates with objects conforming to
   the Target interface.
 Adapter:             [Structural Patterns]
   UML Notification:
 Composite:                               [Structural Patterns]
   Definition:
           Compose objects into tree structures to represent part-
   whole hierarchies.
           Lets clients treat individual objects and compositions
   of objects uniformly.
   Participants:
   Component (DrawingElement): declares the interface for
   objects in the composition.
   implements default behavior for the interface common to all
   classes, as appropriate.
   declares an interface for accessing and managing its child
   components.
   (optional) defines an interface for accessing a component's
   parent in the recursive structure, and implements it if that's
   appropriate.
 Composite:                             [Structural Patterns]
   Participants:
   Leaf (PrimitiveElement): represents leaf objects in the
   composition.
   A leaf has no children.
   defines behavior for primitive objects in the composition.
   Composite (CompositeElement): defines behavior for
   components having children.
   stores child components.
   implements child-related operations in the Component
   interface.
   Client (CompositeApp):manipulates objects in the composition
   through the Component interface.
 Composite:           [Structural Patterns]
   UML Notification:
 Facade:                                   [Structural Patterns]
   Definition:
           Provide a unified interface to a set of interfaces in a
   subsystem.
           defines a higher-level interface that makes the
   subsystem easier to use.
   Participants:
   Façade (MortgageApplication): knows which subsystem classes
   are responsible for a request.
   delegates client requests to appropriate subsystem objects
   Subsystem classes (Bank,Credit,Loan) implement subsystem
   functionality.
   handle work assigned by the Facade object.
   have no knowledge of the facade and keep no reference to it
 Facade:              [Structural Patterns]
   UML Notification:




                              Code Example
 Command:                                 [Behavioral Patterns]
   Definition:
            Encapsulate a request as an object.
            thereby letting parameterize clients with different
   requests, queue or log requests, and support undoable operations
   Participants:
   Command (Command): declares an interface for executing an
   operation.
   ConcreteCommand (CalculatorCommand): defines a binding
   between a Receiver object and an action.
   implements Execute by invoking the corresponding operation(s) on
   Receiver.
   Client (CommandApp) : creates a ConcreteCommand object and
   sets its receiver .
   Invoker (User): asks the command to carry out the request.
   Receiver (Calculator): knows how to perform the operations
   associated with carrying out the request.
 Command:             [Behavioral Patterns]
   UML Notification:
 Iterator:                                [Behavioral Patterns]
    Definition:
            Provide a way to access the elements of an aggregate
    object sequentially without exposing its underlying
    representation.
    Participants:
    Iterator (AbstractIterator): defines an interface for accessing
    and traversing elements.
    ConcreteIterator (Iterator): implements the Iterator interface.
    keeps track of the current position in the traversal of the
    aggregate.
    Aggregate (AbstractCollection): defines an interface for
    creating an Iterator object.
    ConcreteAggregate (Collection): implements the Iterator
    creation interface to return an instance of the proper
    ConcreteIterator.
 Iterator:             [Behavioral Patterns]
    UML Notification:
 Observer:                                [Behavioral Patterns]
   Definition:
           Define a one-to-many dependency between objects so
   that when one object changes state, all its dependents are
   notified and updated automatically.
   Participants:
   Subject (Stock): knows its observers. Any number of Observer
   objects may observe a subject provides an interface for
   attaching and detaching Observer objects.
   ConcreteSubject (IBM): stores state of interest to
   ConcreteObserver.
   sends a notification to its observers when its state changes.
   Observer (Iinvestor): defines an updating interface for objects
   that should be notified of changes in a subject.
   ConcreteObserver (Investor): maintains a reference to a
   ConcreteSubject object.
 Observer:                       [Behavioral Patterns]
   Participants:
   ConcreteObserver (Investor): stores state that should stay
   consistent with the subject's.
   implements the Observer updating interface to keep its state
   consistent with the subject's.
 Observer:            [Behavioral Patterns]
   UML Notification:




                              Code Example
 Strategy:                                [Behavioral Patterns]
   Definition:
          Define a family of algorithms, encapsulate each one,
   and make them interchangeable.
   Lets the algorithm vary independently from clients that use it.
   Participants:
   Strategy (SortStrategy): declares an interface common to all
   supported algorithms. Context uses this interface to call the
   algorithm defined by a ConcreteStrategy.
   ConcreteStrategy (QuickSort, ShellSort, MergeSort) :
   implements the algorithm using the Strategy interface.
   Context (SortedList) : is configured with a ConcreteStrategy
   object .
   maintains a reference to a Strategy object.
   may define an interface that lets Strategy access its data.
 Strategy:            [Behavioral Patterns]
   UML Notification:
 Comparison tally of design patterns:

  S No    Category                Pattern   Usage
    1     Creational    Abstract Factory
    2                   Builder
    3                   Factory Method
    4                   Prototype
    5                   Singleton
    6      Structural   Adapter
    7                   Bridge
    8                   Composite
    9                   Decorator
    10                  Facade
    11                  Flyweight
    12                  Proxy
 Comparison tally of design patterns:

  S No    Category                Pattern        Usage
    13    Behavioral   Chain of Responsibility
    14                 Command

    15                 Interpretor
    16                 Iterator
    17                 Mediator
    18                 Memento
    19                 Observer
    20                 State
    21                 Strategy
    22                 Template Method
    23                 Visitor
 Observer Design Pattern: Optimizing Performance




Requirements:
    Each Order is associated with one Customer and one SalesPerson.
    Each Order includes various OrderDetail transactions. [Relationship One to Many]
 Observer Design Pattern: Optimizing Performance




Requirements:
user wants to view Report or Dashboard including total sales amount for each product, total
sold amount each sales person sells, and total payment amount each customer pays.
 Observer Design Pattern: Optimizing Performance




Solution:
Making sum once, storing it in the database.
Customer:        Add field “TotalPaymentAmount”
Product:         Add field “TotalSalesAmount”
SalesPerson:     Add field “TotalSoldAmount”
 Observer Design Pattern: Optimizing Performance




Solution:
      when SalesPerson updates Order data, system updates 3 total fields too. This gives a
hint about Subscriber-Publisher Model(Observer Pattern).
 Observer Design Pattern: Optimizing Performance




Observer Design Pattern:
defines a one-to-many dependency between objects so that when one object changes state,
all its dependents are notified and updated automatically.
 Design Pattern: Real world challenges
• What kind of evidence do we need to have to know that a pattern
is of general use in design?
• What are the barriers for making a pattern language a useful tool
for the broader community of educators and educational
researchers?
• As the pattern approach becomes more successful, how can we
ensure that pattern authors build on each other’s work, fostering a
culture of knowledge accumulation?
• How is the pattern approach related to other means of knowledge
sharing?
Ref: http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Groups.CAL09/
THANK YOU

Mais conteúdo relacionado

Mais procurados

Lecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patternsop205
 
Design patterns creational patterns
Design patterns creational patternsDesign patterns creational patterns
Design patterns creational patternsMalik Sajid
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanPriyanka Pradhan
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14Niit Care
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns IllustratedHerman Peeren
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of PatternsChris Eargle
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsMichael Heron
 
27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examplesQuang Suma
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 

Mais procurados (20)

Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Sda 8
Sda   8Sda   8
Sda 8
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
 
Lecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patterns
 
Design patterns creational patterns
Design patterns creational patternsDesign patterns creational patterns
Design patterns creational patterns
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
 
27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 

Destaque

Design Patterns (Tasarım Kalıpları)
Design Patterns (Tasarım Kalıpları)Design Patterns (Tasarım Kalıpları)
Design Patterns (Tasarım Kalıpları)nedirtv
 
Patrones de creación
Patrones de creaciónPatrones de creación
Patrones de creaciónAutentia
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in PracticeGanesh Samarthyam
 
Patrones estructurales
Patrones estructuralesPatrones estructurales
Patrones estructuralesJuan Camilo
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programmingPeter Hilton
 
Patrones comportamiento
Patrones comportamientoPatrones comportamiento
Patrones comportamientoJuan Camilo
 
Yazilim mi̇mari̇leri̇(aoy)
Yazilim mi̇mari̇leri̇(aoy)Yazilim mi̇mari̇leri̇(aoy)
Yazilim mi̇mari̇leri̇(aoy)Ahmet Yanik
 

Destaque (7)

Design Patterns (Tasarım Kalıpları)
Design Patterns (Tasarım Kalıpları)Design Patterns (Tasarım Kalıpları)
Design Patterns (Tasarım Kalıpları)
 
Patrones de creación
Patrones de creaciónPatrones de creación
Patrones de creación
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
 
Patrones estructurales
Patrones estructuralesPatrones estructurales
Patrones estructurales
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programming
 
Patrones comportamiento
Patrones comportamientoPatrones comportamiento
Patrones comportamiento
 
Yazilim mi̇mari̇leri̇(aoy)
Yazilim mi̇mari̇leri̇(aoy)Yazilim mi̇mari̇leri̇(aoy)
Yazilim mi̇mari̇leri̇(aoy)
 

Semelhante a Prophecy Of Design Patterns

Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design PatternsDang Tuan
 
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
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa TouchEliah Nikans
 
Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon SomanSisimon Soman
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design patternchetankane
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptAnkitPangasa1
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptbryafaissal
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in briefDUONG Trong Tan
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityShubham Narkhede
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptxSHAHZAIBABBAS13
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Gang of Four in Java
Gang of Four in Java Gang of Four in Java
Gang of Four in Java Mina Tafreshi
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISEsreeja_rajesh
 

Semelhante a Prophecy Of Design Patterns (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
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...
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon Soman
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Gang of Four in Java
Gang of Four in Java Gang of Four in Java
Gang of Four in Java
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
 

Prophecy Of Design Patterns

  • 1. Prophecy of Design Patterns Sep 11th,12th & 13th 2012 By Pradeep Kothiyal
  • 2.  What are design patterns? Design Patterns are:  Recurring solutions to software design problems you find again and again in real-world application development.  A general reusable solution to a commonly occurring problem in software design. - wiki  It is a description or template for how to solve a problem that can be used in many different situations.  Are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.  GoF Patterns are considered the foundation of all design patterns.
  • 3.  What are design patterns? Design Patterns are:  NOT a finished design that can be transformed directly in code.  Object-oriented design patterns shows relationships and interactions between classes or objects without specifying the final application classes or objects that are involved.  Design patterns reside in the domain of modules and interconnections. At a higher level there are Architectural patterns[larger in scope], usually describing an overall pattern followed by an entire system.  NOT ALL software patterns are design patterns. Ex: Algorithms solve computational problems rather than software design problems.
  • 4.  GoF’s contributions in design pattern  Gang of Four was a team of four members: Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. (L-R) Ralph, Erich, Richard and John
  • 5.  GoF’s contributions in design pattern  Profiles:  Erich Gamma: Technical Director at Software Technology Center of OTI at Zurich. Currently working on the IBM Rational Jazz project  Richard Helm: With Boston Consulting Group(BCG) in Sydney, OZ.  Ralph Johnson: Working on the PatternStoriesWiki and promoting the OnLineComputerMuseum. Research Associate Professor in the Department of Computer Science at the University of Illinois at Urbana-Champaign  John Vlissides: Was researcher at IBM's T.J. Watson Research Center. All 23 patterns has been designed by GoF. There are more then 300 design patterns in developer community, which are derived from these 23 patterns.
  • 6.  Three broad visions:  Creational Patterns: are design patterns that deals with Object Creation Mechanism, trying to create objects in a manner suitable to the situation. Ex: Abstract Factory, Factory Method etc.  Structural Patterns: ease the design by identifying a simple way to realize relationship between entities. Ex: Façade, Adapter, Proxy etc.  Behavioral Patterns: Identify common communication patterns between objects and realize these patterns, thus increases flexibility in carrying out this communications. Ex: Observer, Iterator, Command etc.
  • 7.  Commonly used patterns: S No Category Pattern Usage 1 Creational Factory Method* 2 Abstract Factory 3 Singleton 4 Structural Adapter 5 Composite 6 Façade* 7 Behavioral Command 8 Iterator 9 Observer* 10 Strategy *sample examples
  • 8.  Factory Method: [Creational Patterns] Definition: Define an interface for creating an object, but let subclasses decide which class to instantiate. Lets a class defer instantiation to subclasses. Participants: Product (Page) : defines the interface of objects the factory method creates. ConcreteProduct (SkillsPage, EducationPage, ExperiencePage): implements the Product interface Creator (Document) : declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object. may call the factory method to create a Product object. ConcreteCreator (Report, Resume): overrides the factory method to return an instance of a ConcreteProduct.
  • 9.  Factory Method: [Creational Patterns] UML Notification: Code Example
  • 10.  Abstract Factory: [Creational Patterns] Definition: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Participants: AbstractFactory (ContinentFactory): declares an interface for operations that create abstract products. ConcreteFactory (AfricaFactory, AmericaFactory): implements the operations to create concrete product objects. AbstractProduct (Herbivore, Carnivore): declares an interface for a type of product object. Product (Wildebeest, Lion, Bison, Wolf): defines a product object to be created by the corresponding concrete factory. implements the AbstractProduct interface. Client (AnimalWorld): uses interfaces declared by AbstractFactory and AbstractProduct classes.
  • 11.  Abstract Factory: [Creational Patterns] UML Notification:
  • 12.  Singleton: [Creational Patterns] Definition: Ensure a class has only one instance and provide a global point of access to it. Participants: Singleton (LoadBalancer): defines an Instance operation that lets clients access its unique instance. Instance is a class operation. responsible for creating and maintaining its own unique instance. UML Notification:
  • 13.  Adapter: [Structural Patterns] Definition: Convert the interface of a class into another interface clients expect. Lets classes work together that couldn't otherwise because of incompatible interfaces. Participants: Target (ChemicalCompound): defines the domain-specific interface that Client uses. Adapter (Compound): adapts the interface Adaptee to the Target interface. Adaptee (ChemicalDatabank): defines an existing interface that needs adapting. Client (AdapterApp): collaborates with objects conforming to the Target interface.
  • 14.  Adapter: [Structural Patterns] UML Notification:
  • 15.  Composite: [Structural Patterns] Definition: Compose objects into tree structures to represent part- whole hierarchies. Lets clients treat individual objects and compositions of objects uniformly. Participants: Component (DrawingElement): declares the interface for objects in the composition. implements default behavior for the interface common to all classes, as appropriate. declares an interface for accessing and managing its child components. (optional) defines an interface for accessing a component's parent in the recursive structure, and implements it if that's appropriate.
  • 16.  Composite: [Structural Patterns] Participants: Leaf (PrimitiveElement): represents leaf objects in the composition. A leaf has no children. defines behavior for primitive objects in the composition. Composite (CompositeElement): defines behavior for components having children. stores child components. implements child-related operations in the Component interface. Client (CompositeApp):manipulates objects in the composition through the Component interface.
  • 17.  Composite: [Structural Patterns] UML Notification:
  • 18.  Facade: [Structural Patterns] Definition: Provide a unified interface to a set of interfaces in a subsystem. defines a higher-level interface that makes the subsystem easier to use. Participants: Façade (MortgageApplication): knows which subsystem classes are responsible for a request. delegates client requests to appropriate subsystem objects Subsystem classes (Bank,Credit,Loan) implement subsystem functionality. handle work assigned by the Facade object. have no knowledge of the facade and keep no reference to it
  • 19.  Facade: [Structural Patterns] UML Notification: Code Example
  • 20.  Command: [Behavioral Patterns] Definition: Encapsulate a request as an object. thereby letting parameterize clients with different requests, queue or log requests, and support undoable operations Participants: Command (Command): declares an interface for executing an operation. ConcreteCommand (CalculatorCommand): defines a binding between a Receiver object and an action. implements Execute by invoking the corresponding operation(s) on Receiver. Client (CommandApp) : creates a ConcreteCommand object and sets its receiver . Invoker (User): asks the command to carry out the request. Receiver (Calculator): knows how to perform the operations associated with carrying out the request.
  • 21.  Command: [Behavioral Patterns] UML Notification:
  • 22.  Iterator: [Behavioral Patterns] Definition: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Participants: Iterator (AbstractIterator): defines an interface for accessing and traversing elements. ConcreteIterator (Iterator): implements the Iterator interface. keeps track of the current position in the traversal of the aggregate. Aggregate (AbstractCollection): defines an interface for creating an Iterator object. ConcreteAggregate (Collection): implements the Iterator creation interface to return an instance of the proper ConcreteIterator.
  • 23.  Iterator: [Behavioral Patterns] UML Notification:
  • 24.  Observer: [Behavioral Patterns] Definition: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Participants: Subject (Stock): knows its observers. Any number of Observer objects may observe a subject provides an interface for attaching and detaching Observer objects. ConcreteSubject (IBM): stores state of interest to ConcreteObserver. sends a notification to its observers when its state changes. Observer (Iinvestor): defines an updating interface for objects that should be notified of changes in a subject. ConcreteObserver (Investor): maintains a reference to a ConcreteSubject object.
  • 25.  Observer: [Behavioral Patterns] Participants: ConcreteObserver (Investor): stores state that should stay consistent with the subject's. implements the Observer updating interface to keep its state consistent with the subject's.
  • 26.  Observer: [Behavioral Patterns] UML Notification: Code Example
  • 27.  Strategy: [Behavioral Patterns] Definition: Define a family of algorithms, encapsulate each one, and make them interchangeable. Lets the algorithm vary independently from clients that use it. Participants: Strategy (SortStrategy): declares an interface common to all supported algorithms. Context uses this interface to call the algorithm defined by a ConcreteStrategy. ConcreteStrategy (QuickSort, ShellSort, MergeSort) : implements the algorithm using the Strategy interface. Context (SortedList) : is configured with a ConcreteStrategy object . maintains a reference to a Strategy object. may define an interface that lets Strategy access its data.
  • 28.  Strategy: [Behavioral Patterns] UML Notification:
  • 29.  Comparison tally of design patterns: S No Category Pattern Usage 1 Creational Abstract Factory 2 Builder 3 Factory Method 4 Prototype 5 Singleton 6 Structural Adapter 7 Bridge 8 Composite 9 Decorator 10 Facade 11 Flyweight 12 Proxy
  • 30.  Comparison tally of design patterns: S No Category Pattern Usage 13 Behavioral Chain of Responsibility 14 Command 15 Interpretor 16 Iterator 17 Mediator 18 Memento 19 Observer 20 State 21 Strategy 22 Template Method 23 Visitor
  • 31.  Observer Design Pattern: Optimizing Performance Requirements: Each Order is associated with one Customer and one SalesPerson. Each Order includes various OrderDetail transactions. [Relationship One to Many]
  • 32.  Observer Design Pattern: Optimizing Performance Requirements: user wants to view Report or Dashboard including total sales amount for each product, total sold amount each sales person sells, and total payment amount each customer pays.
  • 33.  Observer Design Pattern: Optimizing Performance Solution: Making sum once, storing it in the database. Customer: Add field “TotalPaymentAmount” Product: Add field “TotalSalesAmount” SalesPerson: Add field “TotalSoldAmount”
  • 34.  Observer Design Pattern: Optimizing Performance Solution: when SalesPerson updates Order data, system updates 3 total fields too. This gives a hint about Subscriber-Publisher Model(Observer Pattern).
  • 35.  Observer Design Pattern: Optimizing Performance Observer Design Pattern: defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • 36.  Design Pattern: Real world challenges • What kind of evidence do we need to have to know that a pattern is of general use in design? • What are the barriers for making a pattern language a useful tool for the broader community of educators and educational researchers? • As the pattern approach becomes more successful, how can we ensure that pattern authors build on each other’s work, fostering a culture of knowledge accumulation? • How is the pattern approach related to other means of knowledge sharing? Ref: http://patternlanguagenetwork.myxwiki.org/xwiki/bin/view/Groups.CAL09/