Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

Chapter 1

Introduction

Design Patterns
Elements of Reusable Object-Oriented Software
Design Pattern
Solutions to commonly occurring
problems in object oriented
programming.

2
Purpose of Design Pattern

Not to reinvent the wheel

Collect the experiences and use them


3
Design Pattern
A pattern has four essential elements:
1. Pattern name - used to describe a design
problem, its solutions and consequences in a
word or two.
2. Problem explains the problem and its context,
describes when to apply the pattern.
3. Solution - describes the design
4. Consequences the results and trade-offs of
applying the pattern.

4
Describing Design Patterns
How patterns are described in the book of GOF
Pattern Name and Classification

Intent

Also Known As

Motivation

Applicability

Structure

Participants

5
Describing Design Patterns
(contd.)
Collaborations
Consequences
Implementation
Sample Code
Known Uses
Related Patterns

6
Design pattern
How many design patterns?
- hundreds of patterns are available
- The 23 design patterns by GOF are
well known
- more are to be discovered on the way

7
Classification of Design
Patterns
Design patterns are classified based on two criteria
Purpose reflects what a pattern does
Creational concern the process of object creation
Structural deal with the composition of classes or objects
Behavioral characterize the ways in which classes or
objects interact and distribute responsibility

Scope specifies whether the pattern applies


primarily to classes or to objects
Class patterns deal with relationships between classes
and their subclasses; fixed at compile time; static in nature
Object patterns deal with object relationships, which can
be changed at run-time and are more dynamic
8
Design Pattern Space
Purpose Creational Structural Behavioral
Scope
Class Factory Method Adapter (class) Interpreter
Template Method
Object Abstract Factory Composite Iterator
Builder Adapter Chain of Responsibility
Prototype (object) Command
Singleton Bridge Mediator
Decorator Memento
Faade Observer
Flyweight State
Proxy Strategy
Visitor

9
Guide to Notation
Appendix B + Chapter 1
Guide to Notation
Three different diagrammatic notations are used
A class diagram depicts classes, their structure,
and the static relationships between them
An object diagram depicts a particular object
structure at run-time
An interaction diagram shows the flow of requests
between objects

11
Class Diagram (1)
Abstract and concrete classes
Relationships between classes (uses different
symbols)
Inheritance (triangle)
Part-of or aggregation (arrowheaded line with a
diamond at the base)
Acquaintance (arrowheaded line without diamond)
Creates (dashed arrowheaded line)
Reference to single or multiple objects (filled
circle)
Pseudocode annotations
12
Class Diagram (2)
AbstractClassName

AbstractOperation1()
Type AbstractOperation2()
ConcreteClassName

Operation1()
Type Operation2()

instanceVariable1
Type instanceVariable2

Abstract and concrete classes 13


Class Diagram (3)
More than one
shapes
Drawing Shape

Inheritance
Aggregation

CreationTool LineShape Color

Creates Acquaintance

Class Relationships 14
Class Diagram (4)

Drawing
for each shape {
Draw() shape->Draw()
}

Pseudocode annotation 15
Object Diagram (1)
Shows instances exclusively
Provides a snapshot of the objects in a design
pattern
The objects are named aSomething, where
Something is the class of the object

16
Object Diagram (2)

aDrawing

shape[0]
shape[1]

aLineShape aCircleShape

Object diagram notation 17


Interaction Diagram (1)
Shows the order in which requests between objects
get executed
Time flows from top to bottom
A solid vertical line indicates the lifetime of a
particular object
The vertical line of an object appears dashed until
the point of its creation
A vertical rectangle shows that an object is active
Horizontal arrow: request for an operation
Dashed arrowheaded line: request to create an
object

18
Interaction Diagram (2)
aCreationTool aDrawing aLineShape

new LineShape

Add(aLineShape)
Refresh()

Draw()

Interaction diagram notation 19


Chapter 1(GoF) - Syllabus
Contents of the slides and relevant
sections from the text book
Page 1 11
Appendix B Full

20
Acknowledgement
Sajjadur Rahman Sunny
http://teacher.buet.ac.bd/sunnysajjad/

21

You might also like