design patterns n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Design Patterns PowerPoint Presentation
Download Presentation
Design Patterns

Loading in 2 Seconds...

play fullscreen
1 / 27

Design Patterns - PowerPoint PPT Presentation


  • 268 Views
  • Uploaded on

Design Patterns. William A. Hoffman NYU OOP Class. Design Patterns Overview. Why Design Patterns? History Definitions / Terminology Pattern Examples - from DP book Summary. Why OO Design Patterns . Effective for teaching OOD OOP is a new Art form

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Design Patterns' - brooke


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
design patterns

Design Patterns

William A. Hoffman

NYU OOP Class

design patterns overview
Design Patterns Overview
  • Why Design Patterns?
  • History
  • Definitions / Terminology
  • Pattern Examples - from DP book
  • Summary
why oo design patterns
Why OO Design Patterns
  • Effective for teaching OOD
  • OOP is a new Art form
    • People have only had ~20 years experience with OOP
    • Architecture and painting have been around for thousands of years.
  • Effective method of transferring skill and experience
    • new OO programmers can be overwhelmed by the options
history of design patterns
History of Design Patterns
  • Christopher Alexander - an architect
    • “The Timeless Way of Building”, 1979
    • “A Pattern Language”, 1977
    • Pattern - “ A solution to a problem in a context”
    • Purposes
      • effective reuse
      • dissemination of solutions
history in oop
History in OOP
  • 1987 workshop at OOPSLA Beck and Ward
  • 1993 The Hillside Group - Beck, Ward, Coplien, Booch, Kerth, Johnson
  • 1994 Pattern Languages of Programming (PLoP) Conference
  • 1995 Design Patterns : Elements of Reusable OO software - Gamma, Helm, Johnson, Vlissides (Gang of Four)
definitions terminology
Definitions / Terminology
  • Pattern Language - a term from Christopher Alexander, not a software language but a group of patterns used to construct a whole
  • Pattern - many definitions see FAQ, lets try this one: “Patterns represent distilled experience which, through their assimilation, convey expert insight and knowledge to inexpert developers. “ - Brad Appleton
types of software
Types of Software
  • Application Programs - internal reuse, extension. Excell, PowerPoint
  • Toolkits - set of related, reusable general purpose classes. (Fresco)
  • Frameworks- reusable set of cooperating classes for a specific class of software (TargetJr)
how a pattern is defined gof form
Name - good name

Intent- what does it do

Also Known As

Motivation - a scenario

Applicability - when to use

Structure- UML

Participants - classes

Collaborations - how they work together

Consequences - trade offs

Implementation- hints on implementation

Sample Code

Known Uses

Related Patterns

How a Pattern is Defined(GoF form)
new patterns
New Patterns
  • Rule of 3, should be used in 3 places, it should be a reoccurring pattern, not an algorithm.
  • Each Domain has patterns
purpose of design patterns
Purpose of Design Patterns
  • Creational - Abstact Factory
  • Structural - Adapter, Bridge
  • Behavioral - Iterator, State
singleton creational
Singleton (creational)
  • Intent - ensure a class has only one instance and provide a global point of access
  • Motivation - Some classes must only have one instance, (one file system, one window mgr), allow class to ensure only one instance.
  • Applicability
    • Must be only one instance
    • The one instance should be extensible by subclassing, and clients should be able to use extended version without modification of client
singleton cont
Singleton Cont.
  • Structure

Singleton

return uniqueInstance

static Instance();

SingleOperation();

GetSingletonDate();

static uniqueInstance

singletonData

singleton cont1
Singleton Cont
  • Participants
    • Singleton
    • defines an Instance operation that lets clients access its unique instance, a static or class method is used
  • Collaborations
    • clients access only from the unique instance
slide14

Singleton Cont

  • Consequences
    • controlled access to sole instance
    • reduced name space (no globals)
    • permits refinement via sub-classing
    • permits a variable number of instnaces
    • more flexible than class operations, specifically in c++/java static is not virtual
    • clients access only from the unique instance
slide15

class Singleton

{

public:

static Singleton* Instance();

protected:

Singleton();

private:

static Singleton* _instance;

};

Singleton* Singleton::_instance = 0;

Singleton* Singleton::Instance()

{

if(!_instance)

_instance = new Singleton();

return _instance;

}

singleton cont2
Singleton Cont
  • Sample Code - mazefactory class
  • Known Uses
    • meta class
    • InterViews WidgetKit
  • Related Patterns
    • many patterns use singleton See: Abstarct Factory, Builder and Prototype
proxy
Proxy
  • A surrogate or placeholder for another object to control access to

TCIP

Client1

Image_proxy

ORB

Image (instance)

Client2

Image_proxy

slide18

CacheProxy

Client1

Image_proxy_wcache

ORB

Image (instance)

Client2

Image_proxy_wcache

Can use Observer Pattern to Notify

clients of changes in the source

image class

interaction of patterns
Interaction of Patterns
  • Patterns are often interelated
    • AbstractFactory is often done as a Singleton
  • Observer and Proxy in CORBA
template method
Template Method
  • Intent - Define a skeleton of an algorithm in an operation, deferring some steps to subclasses. Sub-classes can redefine steps in an algorithm without changing its structure
  • Motivation- Document example
  • Applicability
    • implement invariant parts of an algorithm
    • avoid code duplications by noticing common behavior in sub-classes
    • hook extenstions
slide21

AbstractClass

TemplateMethod()

PrimativeOp1();

PrimativeOp2();

PrimativeOp1();

PrimativeOp2();

...

ConcreateClass

PrimativeOp1();

PrimativeOp2();

slide22

// From NeXT AppKit

void View::Display()

{

SetFocus();

DoDisplay();

ResetFocus();

}

void View::DoDisplay() { }

void MyView::DoDisplay() { // do my render

}

overview of patterns in gof design patterns
Creational

Factory Method

Abstract Factory

Builder

Prototype

Singleton

Structural

Adapter

Bridge

Composite

Decorator

Façade

Flyweight

Proxy

Overview of Patterns in GoF Design Patterns
  • Behavioral
    • Interpreter
    • Template Method
    • Chain of Responsibility
    • Command
    • Iterator
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Visitor
design pattern benefits
Design Pattern Benefits
  • Adds to the language of OOP
    • much information is expressed in a single term
  • Documentation
  • Reuse of ideas not just code
  • CORBA problem - found a pattern on the web
  • Anti-Patterns
problems
Problems
  • Classification
  • Tools
  • Formalization
patterns on the web
Patterns on the web
  • Patterns Home Page: http://hillside.net/patterns
  • http://st-www.cs.uiuc.edu/users/patterns/patterns.html
  • http://c2.com/ppr/index.html - Portland Pattern Repository
  • http://www.entract.com/~bradapp/docs/patterns-intro.html
parting quote
Parting Quote
  • It is possible to make buildings by stringing together patterns, in a rather loose way. A building make like this, is an assembly of patterns. It is not dense. It is not profound. But I is also possible to put patterns together in such a way hat many patterns overlap in the same physical space: the building is very dense; it has many meanings captured in a small space; and through this density, it becomes profound.
    • Christopher Alexander