01 Introduction & Decorator PatternDesign Patterns© Prafulla Paraskar 2010
Introduction
Design Patterns - DefinitionDefinition:a general reusable solution to a commonly occurring problem in software design (Wikipedia).Not a finished design Description or template for how to solve a problem that can be used in many different situationsShows relationships and interactions between classes and/or objectsNot all software patterns are design patterns (e.g. algorithms)
Design Patterns – ClassificationStructural PatternEase the design by identifying a simple way to realize relationships between entitiesE.g. Decorator,  ProxyCreational PatternDeal with object creation mechanismE.g. Abstract Factory, SingletonBehavioral PatternDeal with common communication between objects.E.g. Chain of Responsibility, CommandConcurrency PatternDeal with multi-threaded programming paradigm.E.g. Monitor Object, Thread PoolNot covered during this series© Prafulla Paraskar 2010
Design Patterns – Classification
UML Class Diagram Notation (1/3)
UML Class Diagram Notation (2/3)© Prafulla Paraskar 2010
UML Class Diagram Notation (3/3)© Prafulla Paraskar 2010
DecoratorStructural Design Pattern
DefinitionIn object-oriented programming, the decorator pattern is a design pattern that allows new/additional behaviour to be added to an existing object dynamically.© Prafulla Paraskar 2010
Decorator Pattern – Explained (1/2)Photo+Frame+CaptionGuptas (2010)© Prafulla Paraskar 2010
Decorator Pattern – Explained (2/2)Adds functionality at Runtime.The object does not know it is being “decorated”.Three is no one big feature-laden class with all the options in it.The decorations are independent of each other.The decorations can be composed together in a mix-and-match fashion.© Prafulla Paraskar 2010
Decorator Pattern – UML Diagram© Prafulla Paraskar 2010
Decorator Pattern – Real World SamplesGraphics world (as illustrated).I/O namespace of .NETSystem.IO.StreamSystem.IO.BufferedStreamSystem.IO.FileStreamSystem.IO.MemoryStreamCross platform applications (Mobile/Desktop)Actual decorator classes in .NET 3.0System.Windows.Controls (Base Class)Border (Decorator)Viewbox (Decorator)© Prafulla Paraskar 2010
Decorator Pattern – Guidelines (1/2)You have:An existing component class that may be unavailable for subclassing.You want to:Attach additional state or behavior to an object dynamically.Make Changes to some objects of a class without affecting others.Avoid subclassing because too many classes could result.© Prafulla Paraskar 2010
Decorator Pattern – Guidelines (2/2)But consider using instead:The Adapter PatternSets up an interface between different classesThe Composite PatternAggregates an object without also inheriting its interface.The Proxy PatternSpecifically controls access to objects.The Strategy PatternChanges the original object rather than wrapping it.© Prafulla Paraskar 2010
Thank you!http://geekswithblogs.net/technomadPresentation by Prafulla Paraskareprafulla@gmail.com

Design Patterns - 01 Introduction and Decorator Pattern

  • 1.
    01 Introduction &Decorator PatternDesign Patterns© Prafulla Paraskar 2010
  • 2.
  • 3.
    Design Patterns -DefinitionDefinition:a general reusable solution to a commonly occurring problem in software design (Wikipedia).Not a finished design Description or template for how to solve a problem that can be used in many different situationsShows relationships and interactions between classes and/or objectsNot all software patterns are design patterns (e.g. algorithms)
  • 4.
    Design Patterns –ClassificationStructural PatternEase the design by identifying a simple way to realize relationships between entitiesE.g. Decorator, ProxyCreational PatternDeal with object creation mechanismE.g. Abstract Factory, SingletonBehavioral PatternDeal with common communication between objects.E.g. Chain of Responsibility, CommandConcurrency PatternDeal with multi-threaded programming paradigm.E.g. Monitor Object, Thread PoolNot covered during this series© Prafulla Paraskar 2010
  • 5.
    Design Patterns –Classification
  • 6.
    UML Class DiagramNotation (1/3)
  • 7.
    UML Class DiagramNotation (2/3)© Prafulla Paraskar 2010
  • 8.
    UML Class DiagramNotation (3/3)© Prafulla Paraskar 2010
  • 9.
  • 10.
    DefinitionIn object-oriented programming, the decoratorpattern is a design pattern that allows new/additional behaviour to be added to an existing object dynamically.© Prafulla Paraskar 2010
  • 11.
    Decorator Pattern –Explained (1/2)Photo+Frame+CaptionGuptas (2010)© Prafulla Paraskar 2010
  • 12.
    Decorator Pattern –Explained (2/2)Adds functionality at Runtime.The object does not know it is being “decorated”.Three is no one big feature-laden class with all the options in it.The decorations are independent of each other.The decorations can be composed together in a mix-and-match fashion.© Prafulla Paraskar 2010
  • 13.
    Decorator Pattern –UML Diagram© Prafulla Paraskar 2010
  • 14.
    Decorator Pattern –Real World SamplesGraphics world (as illustrated).I/O namespace of .NETSystem.IO.StreamSystem.IO.BufferedStreamSystem.IO.FileStreamSystem.IO.MemoryStreamCross platform applications (Mobile/Desktop)Actual decorator classes in .NET 3.0System.Windows.Controls (Base Class)Border (Decorator)Viewbox (Decorator)© Prafulla Paraskar 2010
  • 15.
    Decorator Pattern –Guidelines (1/2)You have:An existing component class that may be unavailable for subclassing.You want to:Attach additional state or behavior to an object dynamically.Make Changes to some objects of a class without affecting others.Avoid subclassing because too many classes could result.© Prafulla Paraskar 2010
  • 16.
    Decorator Pattern –Guidelines (2/2)But consider using instead:The Adapter PatternSets up an interface between different classesThe Composite PatternAggregates an object without also inheriting its interface.The Proxy PatternSpecifically controls access to objects.The Strategy PatternChanges the original object rather than wrapping it.© Prafulla Paraskar 2010
  • 17.