330 likes | 623 Views
What is Design Patterns ? by Indriati Teknik Informatika – UB. Powerpoint Templates. Outline. Background Pattern origins and history Definition Elements of Design Patterns Desing Patterns are NOT Where Design Patterns are used Describing Design Patterns Types of patterns.
E N D
What is Design Patterns ? by Indriati Teknik Informatika – UB Powerpoint Templates
Outline • Background • Pattern origins and history • Definition • Elements of Design Patterns • Desing Patterns are NOT • Where Design Patterns are used • Describing Design Patterns • Types of patterns
Search for recurring successful designs – emergent designs from practice (via trial and error) Supporting higher levels of reuse (i.e., reuse of designs) is quite challenging Described in Gama, Helm, Johnson, Vlissides 1995 (i.e., “gang of 4 book”) Based on work by Christopher Alexander (an Architect) on building homes, buildings and towns. Background1
Design patterns represent solutions to problems that arise when developing software within a particular context. E.g., problem/solution pairs within a given context Describes recurring design structures Describes the context of usage Background2
Patterns capture the static and dynamic structure and collaboration among key participants in software designs Especially good for describing how and why to resolve nonfunctional issues Patterns facilitate reuse of successful software architectures and designs. Background3
Pattern origins and history • writings of architect Christopher Alexander(coined this use of the term "pattern" ca. 1977-1979) • Kent Beck and Ward Cunningham, Textronix, OOPSLA'87(used Alexander's "pattern" ideas for Smalltalk GUI design) • Erich Gamma, Ph. D. thesis, 1988-1991 • James Coplien, Advanced C++ Idioms book, 1989-1991 • Gamma, Helm, Johnson, Vlissides("Gang of Four“ - GoF)Design Patterns: Elements of Reusable Object-Oriented Software, 1991-1994 • PLoP Conferences and books, 1994-present • Buschmann, Meunier, Rohnert, Sommerland, Stal, Pattern -Oriented Software Architecture: A System of Patterns(“POSA book”)
Definition • … a fully realized form, original, or model accepted or proposed for imitation…[dictionary] • ... describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice [Alexander]
Definition • a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. • [Wikipedia]
Definition • … the abstraction from a concrete form which keeps recurring in specific non-arbitrary contexts [Riehle] • …both a thing and the instructions for making the thing [Coplien] • ...a literary format for capturing the wisdom and experience of expert designers, and communicating it to novices
Design patterns have four essential elements: Pattern name Problem Solution Consequences Elements of Design Patterns
A handle used to describe: a design problem its solutions its consequences Increases design vocabulary Makes it possible to design at a higher level of abstraction Enhances communication “The Hardest part of programming is coming up with good variable [function, and type] names.” Pattern Name
Describes when to apply the pattern Explains the problem and its context May describe specific design problems and/or object structures May contain a list of preconditions that must be met before it makes sense to apply the pattern Problem
Describes the elements that make up the design relationships responsibilities collaborations Does not describe specific concrete implementation Abstract description of design problems and how the pattern solves it Solution
Results and trade-offs of applying the pattern Critical for: evaluating design alternatives understanding costs understanding benefits of applying the pattern Includes the impacts of a pattern on a system’s: flexibility extensibility portability Consequences
Designs that can be encoded in classes and reused as is (i.e., linked lists, hash tables) Complex domain-specific designs (for an entire application or subsystem) They are: “Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.” Design Patterns are NOT
Object-Oriented programming languages [and paradigm] are more amenable to implementing design patterns Procedural languages: need to define Inheritance Polymorphism Encapsulation Where They are Used
Graphical notation is generally not sufficient In order to reuse design decisions the alternatives and trade-offs that led to the decisions are critical knowledge Concrete examples are also important The history of the why, when, and how set the stage for the context of usage Describing Design Patterns
Describe a recurring design structure Defines a common vocabulary Abstracts from concrete designs Identifies classes, collaborations, and responsibilities Describes applicability, trade-offs, and consequences Design Patterns
Alexandrian form (canonical form) Namemeaningful name Problemthe statement of the problem Contexta situation giving rise to a problem Forcesa description of relevant forces and constraints Solutionproven solution to the problem Examples sample applications of the pattern
Alexandrian form (canonical form) Resulting context (force resolution)the state of the system after pattern has been applied Rationale explanation of steps or rules in the pattern Related patternsstatic and dynamic relationship Known useoccurrence of the pattern and its application within existing system
GoF format Pattern name and classification Intent what does pattern do / when the solution works Also known as other known names of pattern (if any) Motivation the design problem / how class and object structures solve the problem Applicability situations where pattern can be applied Structure a graphical representation of classes in the pattern Participants the classes/objects participating and their responsibilities Collaborationsof the participants to carry out responsibilities
GoF format Consequences trade-offs, concerns Implementation hints, techniques Sample codecode fragment showing possible implementation Known uses patterns found in real systems Related patterns closely related patterns
Creational patterns: Deal with initializing and configuring classes and objects Structural patterns: Deal with decoupling interface and implementation of classes and objects Composition of classes or objects Behavioral patterns: Deal with dynamic interactions among societies of classes and objects How they distribute responsibility Types of Patterns
Abstract Factory: Factory for building related objects Builder: Factory for building complex objects incrementally Factory Method: Method in a derived class creates associates Prototype: Factory for cloning new instances from a prototype Singleton: Factory for a singular (sole) instance Creational Patterns
Adapter: Translator adapts a server interface for a client Bridge: Abstraction for binding one of many implementations Composite: Structure for building recursive aggregations Decorator: Decorator extends an object transparently Facade: Simplifies the interface for a subsystem Flyweight: Many fine-grained objects shared efficiently. Proxy: One object approximates another Structural Patterns
Chain of Responsibility: Request delegated to the responsible service provider Command: Request is first-class object Iterator: Aggregate elements are accessed sequentially Interpreter: Language interpreter for a small grammar Mediator: Coordinates interactions between its associates Memento: Snapshot captures and restores object states privately Behavioral Patterns
Observer: Dependents update automatically when subject changes State: Object whose behavior depends on its state Strategy: Abstraction for selecting one of many algorithms Template Method: Algorithm with some steps supplied by a derived class Visitor: Operations applied to elements of a heterogeneous object structure Behavioral Patterns (cont.)
Purpose Creational Structural Behavioral Scope Class Factory method Adapter (class) Interpreter Template method Object Abstract factory Builder Prototype Singleton Adapter (object) Bridge Composite Decorator Façade Flyweight Proxy Chain of responsibility Command Iterator Mediator Memento Observer State Strategy Visitor Design Pattern Space
Scope is the domain over which a pattern applies Class Scope: relationships between base classes and their subclasses (static semantics) Object Scope: relationships between peer objects Some patterns apply to both scopes. Categorization Terms
Abstracts how objects are instantiated Hides specifics of the creation process May want to delay specifying a class name explicitly when instantiating an object Just want a specific protocol Class::Creational
Assignment Presentation topic • Abstract factory+builder • Factory Method+prototype+singleton • Bridge+ Flyweight • Composite+decorator • Adapter +Facade+Proxy • Command+Chain of responsibility • Iterator+Interpreter • Memento+mediator • Template Method+Strategy • Visitor+observer+state • Agile Development
Rules of the class • Run in Seminar Style • Each class consists of two or three student presentations of design patterns • Each presentation is followed by a discussion of the material presented • Prepare a Power-Point presentation • Description of each type of design pattern • A piece of code to representation the type of design pattern • Demo (optional)
Deadline: Sept 22, 2010 Email to : indriati.tif@ub.ac.id Subject : [ topic ]