Design Patterns Difficult to describe abstractly Elements:

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Patterns in a Security Alarm System (SAS) AGENDA Domain Model Domain Model The Patterns The Patterns –Iterator –Observer –Abstract Factory –Singleton.
Patterns in a Security Alarm System (SAS) AGENDA Domain Model Domain Model The Patterns The Patterns –Iterator –Observer –Abstract Factory –Singleton.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
More on the STL vector list stack queue priority_queue.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Templates and the STL.
Data Structures Using C++ 2E
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Containers Overview and Class Vector
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
Object Oriented Programming Elhanan Borenstein Lecture #11 copyrights © Elhanan Borenstein.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
CS342 Data Structures End-of-semester Review S2002.
Behavioral Pattern: Iterator C h a p t e r 5 – P a g e 159 Software can become difficult to manage when a variety of different traversals of a variety.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
Design Patterns Introduction
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
1 The Standard Template Library Drozdek Section 3.7.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Final Exam Review COP4530.
Examples (D. Schmidt et al)
Design Patterns: Brief Examples
Template Method Pattern Iterator Pattern
Introduction to Design Patterns
C++ Templates.
Software Design Patterns
Standard Template Library (STL)
Basic Data Structures.
object oriented Principles of software design
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Basic Data Structures.
ADT Implementations: Templates and Standard Containers
Final Exam Review COP4530.
Object Oriented Design Patterns - Creational Patterns
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
priority_queue<T>
Introduction to Programming
Containers and the Standard Template Library (STL)
Chapter 8: Class Relationships
STL Библиотека стандартных шаблонов
Standard Template Library
Software Design Lecture : 39.
Standard Template Library
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Abstract Data Types (ADTs)
Standard Template Library
Data Structures & Programming
Presentation transcript:

Design Patterns Difficult to describe abstractly Elements: Pattern Name Problem to Solve Solution Consequences: Results and Trade-Offs Higher level abstraction than classes

Example: Singleton Intent: Define a class pattern that is guaranteed to have only one instance, and provide a global point of access to it. Uses A good global variable/class Simulator has one radar, one physical display, etc.

Singleton Implementation Class Singleton { public: static Singleton* Instance(); protected: Singleton(); private: static Singleton* _instance; }; Singleton* Singleton::Instance = 0; Singleton* Singleton::Instance() { if (_instance == 0) { _instance = new Singleton; } return _instance;

Example: Abstract Factory Provide and interface for creating families of related or dependent objects without specifying their concrete class. A system can be created that is independent of how its elements(products) are created, composed, and represented Participants: Abstract Factory (WidgetFactory): interface to the client Concrete Factory(MotifWidgetFactory, MFCWidgetFactory): implements the abstract interface Abstract Product(Window, Scrollbar): what the client sees Concrete Product(MotifWindow, MotifScrollBar): defines the actual object Client: who uses the products via the abstract interfaces

Iterator Goal: Provide a way to sequentially access the elements of an aggregate object without exposing its underlying representation. Using an iterator, it would be possible to replace an array with a linked list or binary tree This construct is heavily used in STL

Iterator Implementation Template <class Item> class Iterator { public: virtual void First() = 0; virtual void Next()= 0; virtual bool IsDone() const = 0; virtual Item CurrentItem const = 0; protected: Iterator(); };

List Iterator Template <class Item> class ListIterator : public Iterator<Item> { public: ListIterator(const List<Item>* aList); virtual void First(); … private: const List<Item>* _list; long _current; };

STL Standard Template Libaray: Part of C++ Objects vector list map & multimap set & multiset deque (double ended queues) stack, queue, priority_queue

STL cont’d All objects have iterators Generic Algorithms can be done on these objects for_each, find, count, equal, search, sort, fill, merge, etc.