Design Patterns - 01 Introduction and Decorator Pattern


Published on

This is the first presentation of multi part series on design patterns. It covers introduction to design pattern and decorator pattern.

Published in: Design
  • Hi Puja, Appreciate you taking time to go through the slides. Just made the download available on this deck.
    Are you sure you want to  Yes  No
    Your message goes here
  • how to download this ppt???/
    Are you sure you want to  Yes  No
    Your message goes here

Design Patterns - 01 Introduction and Decorator Pattern

  1. 1. 01 Introduction & Decorator Pattern<br />Design Patterns<br />© Prafulla Paraskar 2010<br />
  2. 2. Introduction<br />
  3. 3. Design Patterns - Definition<br />Definition:<br />a general reusable solution to a commonly occurring problem in software design (Wikipedia).<br />Not a finished design <br />Description or template for how to solve a problem that can be used in many different situations<br />Shows relationships and interactions between classes and/or objects<br />Not all software patterns are design patterns (e.g. algorithms)<br />
  4. 4. Design Patterns – Classification<br />Structural Pattern<br />Ease the design by identifying a simple way to realize relationships between entities<br />E.g. Decorator, Proxy<br />Creational Pattern<br />Deal with object creation mechanism<br />E.g. Abstract Factory, Singleton<br />Behavioral Pattern<br />Deal with common communication between objects.<br />E.g. Chain of Responsibility, Command<br />Concurrency Pattern<br />Deal with multi-threaded programming paradigm.<br />E.g. Monitor Object, Thread Pool<br />Not covered during this series<br />© Prafulla Paraskar 2010<br />
  5. 5. Design Patterns – Classification<br />
  6. 6. UML Class Diagram Notation (1/3)<br />
  7. 7. UML Class Diagram Notation (2/3)<br />© Prafulla Paraskar 2010<br />
  8. 8. UML Class Diagram Notation (3/3)<br />© Prafulla Paraskar 2010<br />
  9. 9. Decorator<br />Structural Design Pattern<br />
  10. 10. Definition<br />In object-oriented programming, the decorator pattern is a design pattern that allows new/additional behaviour to be added to an existing object dynamically.<br />© Prafulla Paraskar 2010<br />
  11. 11. Decorator Pattern – Explained (1/2)<br />Photo<br />+<br />Frame<br />+<br />Caption<br />Guptas (2010)<br />© Prafulla Paraskar 2010<br />
  12. 12. Decorator Pattern – Explained (2/2)<br />Adds functionality at Runtime.<br />The object does not know it is being “decorated”.<br />Three is no one big feature-laden class with all the options in it.<br />The decorations are independent of each other.<br />The decorations can be composed together in a mix-and-match fashion.<br />© Prafulla Paraskar 2010<br />
  13. 13. Decorator Pattern – UML Diagram<br />© Prafulla Paraskar 2010<br />
  14. 14. Decorator Pattern – Real World Samples<br />Graphics world (as illustrated).<br />I/O namespace of .NET<br />System.IO.Stream<br />System.IO.BufferedStream<br />System.IO.FileStream<br />System.IO.MemoryStream<br />Cross platform applications (Mobile/Desktop)<br />Actual decorator classes in .NET 3.0<br />System.Windows.Controls (Base Class)<br />Border (Decorator)<br />Viewbox (Decorator)<br />© Prafulla Paraskar 2010<br />
  15. 15. Decorator Pattern – Guidelines (1/2)<br />You have:<br />An existing component class that may be unavailable for subclassing.<br />You want to:<br />Attach additional state or behavior to an object dynamically.<br />Make Changes to some objects of a class without affecting others.<br />Avoid subclassing because too many classes could result.<br />© Prafulla Paraskar 2010<br />
  16. 16. Decorator Pattern – Guidelines (2/2)<br />But consider using instead:<br />The Adapter Pattern<br />Sets up an interface between different classes<br />The Composite Pattern<br />Aggregates an object without also inheriting its interface.<br />The Proxy Pattern<br />Specifically controls access to objects.<br />The Strategy Pattern<br />Changes the original object rather than wrapping it.<br />© Prafulla Paraskar 2010<br />
  17. 17. Thank you!<br /><br />Presentation by Prafulla<br />