SDSU CS 635: Advanced Object-Oriented Design & Programming
Spring Semester, 1998
Design Patterns Intro

To Lecture Notes Index
San Diego State University -- This page last updated 11-Feb-98

Contents of Doc 4, Design Patterns Intro

...References slide # 1
...Design Patterns slide # 2
......OMT-Based Notation slide # 4
......Design Principle 1 slide # 8
......Design Principle 2 slide # 10
......Parameterized Types slide # 11
......Designing for Change slide # 12


Doc 4, Design Patterns Intro Slide # 1

References


Design Patterns: Elements of Resuable Object-Oriented Software, Gamma, Helm, Johnson, Vlissides, Addison-Wesley, 1995
Doc 4, Design Patterns Intro Slide # 2

Design Patterns

What is a Pattern?

"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"

Christopher Alexander


A pattern has four essential elements

Pattern name

Problem

Solution

"the pattern provides an abstract description of a design problem and a general arrangement of elements solves it"

Consequences

Doc 4, Design Patterns Intro Slide # 3

Purpose
ScopeCreationalStructuralBehavioral
ClassFactory MethodAdapterInterpreter
Template Method
ObjectAbstract factory
Builder
Prototype
Singleton
Adapter
Bridge
Composite
Facade
Flyweight
Proxy
Chain of Responsibility
Command
Iterator
Mediator
Memento
State
Strategy
Visitor


Doc 4, Design Patterns Intro Slide # 4

OMT-Based Notation Examples from Text


Class Diagram



Object Diagram



Inheritance


Doc 4, Design Patterns Intro Slide # 5
OMT-Based Notation Examples from Text

Abstract and Implementation




Class Relations




Creating


Doc 4, Design Patterns Intro Slide # 6
OMT-Based Notation Examples from Text

Object Interaction



Doc 4, Design Patterns Intro Slide # 7

Object, Classes and Type (Again)


Signature
An operations name, parameters, and return type

Interface
Set of all signatures defined by an object's operations

Type
A name used to denote a particular interface

Objects may have many types
Different objects in share a type

Subtype
A type is a subtype of another it its interface contains the interface of its supertype

Class
A class defines an object's implementation

Doc 4, Design Patterns Intro Slide # 8

Design Principle 1


Program to an interface, not an implementation

Use abstract classes (and/or interfaces in Java) to define common interfaces for a set of classes

Declare variables to be instances of the abstract class not instances of particular classes


Benefits of programming to an interface



Doc 4, Design Patterns Intro Slide # 9
Programming to an Interface - Example





class A 
     {
     DateServer myServer;

     public operation()
          { myServer.someOp(); }
     }

class B 
     {
     ServerEngine myServer;

     public operation()
          { myServer.someOp(); }
     }

Doc 4, Design Patterns Intro Slide # 10

Design Principle 2


Favor object composition over class inheritance


Composition

Allows behavior changes at run time

Helps keep classes encapsulated and focused on one task

Reduce implementation dependencies


Doc 4, Design Patterns Intro Slide # 11

Parameterized Types


Generics in Ada or Eiffel
Templates in C++

Allows you to make a type as a parameter to a method or class

template <class TypeX>
TypeX min(  TypeX a, Type b )
     {
     return a < b ? a  :  b;
     }

Parameterized types give a third way to compose behavior in an object-oriented system


Doc 4, Design Patterns Intro Slide # 12

Designing for Change


Some common design problems with design patterns that address the problem



visitors since 11-Feb-98