SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to Design Patterns

bessie avatar
4 diapositives · 328 Views · Jul 14, 2014

Introduction to Design Patterns. This lecture will introduce the idea of design patterns What they are and how they are structured We’ll talk about specific patterns several times this semester Today: Iterator and Factory Method After we’ve studied C++ objects: Adapter, Memento, Observer

Introduction to Design Patterns - slide 1
01 / 4Introduction to Design Patterns
1 / 17

Télécharger la présentation

Introduction to Design Patterns
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Introduction to Design Patterns • This lecture will introduce the idea of design patterns • What they are and how they are structured • We’ll talk about specific patterns several times this semester • Today: Iterator and Factory Method • After we’ve studied C++ objects: Adapter, Memento, Observer • After we’ve studied C++ memory: Singleton, Prototype, Visitor

  2. What’s 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 don’t 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 • Don’t want to know/manage details of how they’re 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 list<int>::iterator

  4. 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 we’ll use) Consequences Type that’s created matches type(s) it’s used with Example vector<double> v; vector<double>::iterator i = v.begin(); Factory Method Pattern