Introduction to Design Patterns - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Design Patterns

Description:

The Iterator pattern has been discussed in some detail (STL lectures) ... We'll add a market to mediate event triggered open trading of securities ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 5
Provided by: cseW
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Design Patterns


1
Introduction to Design Patterns
  • This lecture will introduce the idea of design
    patterns
  • What they are and how they are structured
  • Well talk about specific patterns several times
    this semester
  • Today Iterator and Factory Method
  • After weve studied C objects Adapter,
    Memento, Observer
  • After weve studied C memory Singleton,
    Prototype, Visitor

2
Whats a Design Pattern?
  • A design pattern has a name
  • So when someone says Adapter you know what they
    mean
  • So you can communicate design ideas as a
    vocabulary
  • A design pattern describes the core of a solution
    to a recurring design problem
  • So you dont have to reinvent known design
    techniques
  • So you can benefit from others (and your) prior
    experience
  • A design pattern is capable of generating many
    distinct design decisions in different
    circumstances
  • So you can apply the pattern repeatedly as
    appropriate
  • So you can work through different design problems
    using it

3
Iterator Pattern
  • Problem
  • Want to access aggregated elements sequentially
  • E.g., traverse a container of values, objects
    etc. and print them out
  • Context
  • Dont want to know/manage details of how theyre
    stored
  • E.g., could be in an array, list, vector, or
    deque
  • Solution core
  • Provide a common interface for iteration over a
    container (1) start (2) access (3)
    increment (4) termination
  • Consequences
  • Frees user from knowing details of how elements
    are stored
  • Decouples containers from algorithms (crucial in
    C STL)
  • Example
  • listltintgtiterator

4
Factory Method Pattern
  • Problem
  • You want a type to create a related type
    polymorphically
  • E.g., a container should create appropriate begin
    and end iterators
  • Context
  • Each type knows which related type it should
    create
  • Solution core
  • Polymorphic creation
  • E.g., abstract method that different types
    override
  • E.g., provide traits and common interface (as in
    the STL well use)
  • Consequences
  • Type thats created matches type(s) its used
    with
  • Example
  • vectorltdoublegt v vectorltdoublegtiterator i
    v.begin()
Write a Comment
User Comments (0)
About PowerShow.com