Title: Design Patterns
1Design Patterns
Contents
- Terminology in object-oriented design
- Categorizing and selecting design patterns
2Terminology
- Object Interface
a. Signature of a method
- Toolkits
- Frameworks
- Design Patterns
3Object Interface
Every method in the class has its own unique
signature
return_type
name
(parameter types)
The set of all signatures defined by an objects
methods or operations is called the object
interface.
methods
This interface characterizes the complete set of
requests that can be sent to the object.
4Specifying Object Interfaces
Signature of a method
Interface
Possible message recipients
5Implementation of an Interface in C
Interface provided by an abstract class
Concrete realizations receive the messages
6Class Hierarchy
Messages directed to a Shape object can be
received by instances of any of these concrete
classes.
7Toolkits
A toolkit is a set of related and reusable
classes designed to provide general-purpose
functionality. Gamma et al.
Examples
Collection classes Vector, Stack, Queue, List,
etc
Found in libraries such as java.util or the C
STL
The C stream library
8Frameworks
A framework is a set of cooperating classes that
make up a reusable design for a specific class of
software. Gamma, et al.
The framework dictates the architecture of your
application. It captures the design decisions
that are common to the domain of the application.
It establishes the partitioning into classes and
objects and the pattern of collaboration between
objects.
Frameworks promote design reuse
Example the java awt
9Design Patterns
Patterns capture solutions to particular design
problems. They provide for the reuse of
successful designs.
Incorporate design experience.
A design pattern is like a template that can be
applied in many different situations.
A design pattern provides an abstract description
of a design problem and how a general arrangement
of elements (classes and objects) solves it.
Gamma et al.
10Elements of a Design Pattern
Pattern Name
Names allow the designer to work at a higher
level of abstraction. Names make it easier to
talk about and think about designs.
Description of the problem
Describes the problem and its context.
The Solution
Describes the classes that make up the design,
their relationships, and collaborations.
The Consequences
The results and tradeoffs of applying the pattern.
11Categories of Design Patterns
Partial listing
12Notation
Symbol
Meaning
Aggregation
Object A instantiates B
B is a subclass of A
Comment box
13Command Pattern
Intent
Encapsulate a request as an object letting you
- Parameterize clients with different requests
14Command Pattern
Structure
15Command Pattern
Participants
-- declares an interface for executing an
operation
-- defines a binding between a Receiver object
and an action
--implements execute() by invoking the
corresponding operation(s) on Receiver
-- creates a ConcreteCommand object and sets its
receiver
--asks the command to carry out the request
--knows how to carry out the request. (Any class
may serve as Receiver)
16Command Pattern
Collaborations
17Command Pattern
Collaborations
- The Client creates a ConcreteCommand object and
specifies its receiver. - An Invoker object stores the ConcreteCommand
object. - The invoker issues a request by calling execute(
) on the command. When commands are undoable,
ConcreteCommand stores state for undoing prior
to invoking execute( ). - The ConcreteCommand object invokes operations on
its receiver to carry out the request.
18Command Pattern
Consequences
- Command decouples the object that invokes the
operation from the one that knows how to perform
it. - Commands are first-class objects. They can be
manipulated and extended like any other object. - Its easy to add new Commands, because you dont
have to change existing classes. - Commands can be assembled into a composite
command.
19run( )
20Further Information about Design Patterns
Design Patterns Home Page
Links of particular interest
Doug Leas FAQ on Design Patterns
Setting up a Design Pattern study group