Download presentation
Presentation is loading. Please wait.
1
Design Patterns
2
What is a Design Pattern? Generic pattern for solving a certain class of problem Learn to recognize the class of problem and apply a solution you already know A more structured/systematic way of thinking about program design
3
Common Patterns Functor Adapter Iterator Composite Observer
4
Functor A class with a single function and no data Often used to compare two objects Pass to a function objects to be compared and a functor object that can compare them Example: a different implementation of SortedList More generally: you may want to have a class that knows how to perform a function on given data, but does not store the data or results
5
Adapter/Wrapper Change or extend the interface of a class –May also wrap primitive types Example: miles to km
6
Iterator Goal: an interface that will allow the programmer to traverse through any collection Operations: bool hasNext() const Object & next() Example: iterate through SortedList of names
7
Iterator Example Code http://www.cs.fiu.edu/~weiss/adspc++2/code/Iterator1.cpp http://www.cs.fiu.edu/~weiss/adspc++2/code/Iterator3.cpp
8
Composite An object containing two other objects –Key, value pairs Idea: group together so that both can be returned from a function Example from Project 1?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.