References: Xiaoping Jia, Object-Oriented Software Development
Using Java;Douglas C.Schmidt, Design Pattern Case Studies with
C++
1
Design Patterns
• Generic (reusable) solutions to a recurring
problem
• Evolved from Christopher Alexander’s
patterns for architecture.
– “Each pattern 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 et. al., A Pattern Language (Oxford
U.Press,1977)
2
Design Patterns–a ‘Hot Topic’
• OOPSLA Workshops – 17%
– Patterns for Software Architecture
– Killer Examples for Design Patterns &
Objects First
– Patterns in Distributed Real Time &
Embedded Systems
– Patterns for Customer Interaction &
Expectation Management
– Software Development Process Patterns
3
Design Patterns–a ‘Hot Topic’
• OOPSLA Tutorials – 20%
– Pattern-oriented Software Architectures for Networked and
Concurrent Applications
– Patterns of Enterprise Application Architecture
– Patterns at Work
– Patterns for Writing Effective Use Cases
– Dungeons and Patterns!
– Patterns and Application Experiences for Real-time Object
Request Brokers
– Refactoring to Patterns
– Object-oriented Reengineering: Patterns & Techniques
– Patterns for EJB Development
– How to Use Design Patterns in Java and .NET
4
Design Patterns
• Categories of Software Design Patterns
– Creational : deal with process of creation
– Structural : deal with static composition
and structure of classes and objects
– Behavioral : deal with dynamic interaction
among classes and objects
5
Design Patterns
• Each pattern is described as follows:
Pattern name
Category : creational, structural or behavioral
Intent : short description of problem addressed
AKA: other names for the pattern
Applicability : where pattern can be applied
Structure : diagram that describes participants
in the pattern & relationships among them
Participants : list of classes and/or objects that
participate in the pattern
6
Singleton Pattern
• Category: creational
• Intent: ensure that a class has only one
instance and provide global point of
access to it
• Applicability: use where there must be
exactly one instance of a class and it
must be accessible to clients from a
well-known access point (e.g. database)
7
Singleton Pattern
• Structure
Singleton
static getInstance()
return theInstance
operation()
getData()
static Singleton theInstance
data
8
Singleton Pattern
• Participants : only one
• Singleton declares the unique instance
of the class as a static variable and
defines a static method getInstance() for
clients to access the unique instance.
9
Singleton Pattern
public class Singleton {
public static Singleton getInstance() {
return theInstance;
}
private Singleton() {
//initialize instance fields
}
//….
private static Singleton theInstance = new Singleton();
}
10
Strategy Pattern
• Category : behavioral
• Intent: define a family of algorithms,
encapsulate each one and make them
interchangeable
11
Strategy Pattern
• Applicability: use when
– many related classes differ only in behavior
• plotting different functions
– different variations of algorithm are needed
• sorts
– an algorithm uses data that clients should
not know about
• LayoutManager in the AWT
– a class defines many behaviors which
appear as multiple conditional statements
in its methods
12
Structure of Strategy Pattern
STRATEGY
Context
contextInterface()
Strategy
algorithmInterface()
Concrete Strategy A
algorithmInterface()
Concrete Strategy C
algorithmInterface()
Concrete Strategy B
algorithmInterface()
Note: arrowheads should be unfilled
13
Using the Strategy Pattern
Pivot Strategy
getPivot()
quicksort
pivotStrategy.getPivot(array,lo,hi)
Select
First
Random
Median
of
Three
Concrete
Strategies
Strategy pattern resolves how to extend policies for selecting a
pivot value without modifying main quicksort algorithm
14
A tutorial presented by Steve Metsker and William Wake
At OOPSLA 2001
15
Why Design Patterns?
• Patterns record previous successes
in a reusable form
• Design patterns are well-worn
solutions to problems at about a
class level
16
How the Game Works
• Each table has a pattern master
who has a map of a dungeon
• You must adventure through the
dungeon to reclaim pearls of
wisdom from a dragon
• Your primary helper is an Ahobbit
– With capricious magical abilities
17
Ahobbits
• Your Ahobbit has a magical ring that
– Cannot be removed
– You can activate by getting him/her to say
“Aha”
• Ahobbits are enlightened only when
they understand a design pattern
• Ahobbits learn from real-world
examples in the dungeon
18
Adventuring
• Find a room in the dungeon
• When you enter
– Examine the device or contents therein
– Determine which pattern it shows
– Use the device to explain to your Ahobbit
the intent of the pattern (2 guesses)
• When the Ahobbit says “Aha,”
something magical will occur
19
Beginning
• We shall begin as one huge
exploration party
• Before breaking into one party per
table or group
• You stand before a door that leads to
the dungeon
• What do you do?
20
21
© Copyright 2026 Paperzz