Design Patterns - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Design Patterns

Description:

Design Patterns Contents Terminology in object-oriented design Mechanisms for reuse Designing for change Categorizing and selecting design patterns – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 21
Provided by: jamest92
Category:

less

Transcript and Presenter's Notes

Title: Design Patterns


1
Design Patterns
Contents
  • Terminology in object-oriented design
  • Mechanisms for reuse
  • Designing for change
  • Categorizing and selecting design patterns

2
Terminology
  1. Object Interface

a. Signature of a method
  1. Toolkits
  1. Frameworks
  1. Design Patterns

3
Object 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.
4
Specifying Object Interfaces
Signature of a method
  • name
  • parameters
  • return type

Interface
Possible message recipients
5
Implementation of an Interface in C
Interface provided by an abstract class
Concrete realizations receive the messages
6
Class Hierarchy
Messages directed to a Shape object can be
received by instances of any of these concrete
classes.
7
Toolkits
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
8
Frameworks
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
9
Design 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.
10
Elements 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.
11
Categories of Design Patterns
Partial listing
12
Notation
Symbol
Meaning
Aggregation
Object A instantiates B
B is a subclass of A
Comment box
13
Command Pattern
Intent
Encapsulate a request as an object letting you
  • Parameterize clients with different requests
  • Queue or log requests
  • Support undo operations

14
Command Pattern
Structure
15
Command Pattern
Participants
  • Command

-- declares an interface for executing an
operation
  • ConcreteCommand

-- defines a binding between a Receiver object
and an action
--implements execute() by invoking the
corresponding operation(s) on Receiver
  • Client (Applicatiojn)

-- creates a ConcreteCommand object and sets its
receiver
  • Invoker (Menuitem)

--asks the command to carry out the request
  • Receiver (Document)

--knows how to carry out the request. (Any class
may serve as Receiver)
16
Command Pattern
Collaborations
17
Command Pattern
Collaborations
  1. The Client creates a ConcreteCommand object and
    specifies its receiver.
  2. An Invoker object stores the ConcreteCommand
    object.
  3. The invoker issues a request by calling execute(
    ) on the command. When commands are undoable,
    ConcreteCommand stores state for undoing prior
    to invoking execute( ).
  4. The ConcreteCommand object invokes operations on
    its receiver to carry out the request.

18
Command Pattern
Consequences
  1. Command decouples the object that invokes the
    operation from the one that knows how to perform
    it.
  2. Commands are first-class objects. They can be
    manipulated and extended like any other object.
  3. Its easy to add new Commands, because you dont
    have to change existing classes.
  4. Commands can be assembled into a composite
    command.

19
run( )
20
Further 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
Write a Comment
User Comments (0)
About PowerShow.com