33
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB

Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB

Embed Size (px)

Citation preview

Powerpoint TemplatesPage 1

Powerpoint Templates

What is Design Patterns ?

by IndriatiTeknik Informatika – UB

Powerpoint TemplatesPage 2

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

Powerpoint TemplatesPage 3

Background1

• 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.

Powerpoint TemplatesPage 4

Background2

• 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

Powerpoint TemplatesPage 5

Background3

• 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.

Powerpoint TemplatesPage 6

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”)

Powerpoint TemplatesPage 7

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]

Powerpoint TemplatesPage 8

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]

Powerpoint TemplatesPage 9

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

Powerpoint TemplatesPage 10

Elements of Design Patterns

• Design patterns have four essential elements:– Pattern name– Problem– Solution– Consequences

Powerpoint TemplatesPage 11

Pattern Name• 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.”

Powerpoint TemplatesPage 12

Problem• 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

Powerpoint TemplatesPage 13

Solution• 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

Powerpoint TemplatesPage 14

Consequences• 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

Powerpoint TemplatesPage 15

Design Patterns are NOT

• 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.”

Powerpoint TemplatesPage 16

Where They are Used• Object-Oriented programming

languages [and paradigm] are more amenable to implementing design patterns

• Procedural languages: need to define– Inheritance– Polymorphism– Encapsulation

Powerpoint TemplatesPage 17

Describing Design Patterns• 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

Powerpoint TemplatesPage 18

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

Powerpoint TemplatesPage 19

Alexandrian form (canonical form)Name

meaningful nameProblem

the statement of the problemContext

a situation giving rise to a problemForces

a description of relevant forces and constraints

Solution proven solution to the problem

Examples sample applications of the pattern

Powerpoint TemplatesPage 20

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 patterns static and dynamic relationship

Known useoccurrence of the pattern and its application within existing system

Powerpoint TemplatesPage 21

GoF formatPattern 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

Collaborations of the participants to carry out responsibilities

Powerpoint TemplatesPage 22

GoF formatConsequences

trade-offs, concerns

Implementation hints, techniques

Sample code code fragment showing possible implementation

Known uses patterns found in real systems

Related patterns

closely related patterns

Powerpoint TemplatesPage 23

Types of 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

Powerpoint TemplatesPage 24

Creational 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

Powerpoint TemplatesPage 25

Structural 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

Powerpoint TemplatesPage 26

Behavioral 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

Powerpoint TemplatesPage 27

Behavioral Patterns (cont.)

• 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

Powerpoint TemplatesPage 28

Design Pattern Space

Chain of responsibility

Command

Iterator

Mediator

Memento

Observer

State

Strategy

Visitor

Adapter (object)

Bridge

Composite

Decorator

Façade

Flyweight

Proxy

Abstract factory

Builder

Prototype

Singleton

Object

Interpreter

Template method

Adapter (class)Factory methodClassScope

BehavioralStructuralCreational

Purpose

Powerpoint TemplatesPage 29

Categorization Terms

• 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.

Powerpoint TemplatesPage 30

Class::Creational

• 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

Powerpoint TemplatesPage 31

AssignmentPresentation topic

1. Abstract factory+builder

2. Factory Method+prototype+singleton

3. Bridge+ Flyweight

4. Composite+decorator  

5. Adapter +Facade+Proxy

6. Command+Chain of responsibility

7. Iterator+Interpreter

8. Memento+mediator 

9. Template Method+Strategy

10. Visitor+observer+state

11. Agile Development

Powerpoint TemplatesPage 32

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)

Powerpoint TemplatesPage 33

Deadline: Sept 22, 2010

Email to : [email protected]

Subject : [ topic ]