pattern-examples4 - Object-Oriented Design Case Studies...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Object-Oriented Design Case Studies with Patterns and C++ Douglas C. Schmidt Professor Department of EECS [email protected] Vanderbilt University www.cs.wustl.edu/ schmidt/ (615) 343-8197 OO Pattern Examples Douglas C. Schmidt Case Studies Using Patterns The following slides describe several case studies using C++ and patterns to build highly extensible software The examples include 1. System Sort – e.g. , Facade, Adapter, Iterator, Singleton, Factory Method, Strategy, Bridge, Double-Checked Locking Optimization 2. Sort Verifier – e.g. , Strategy, Factory Method, Facade, Iterator, Singleton Vanderbilt University 1 OO Pattern Examples Douglas C. Schmidt Case Study 1: System Sort Develop a general-purpose system sort – It sorts lines of text from standard input and writes the result to standard output – e.g. , the UNIX system sort In the following, we’ll examine the primary forces that shape the design of this application For each force, we’ll examine patterns that resolve it Vanderbilt University 2 OO Pattern Examples Douglas C. Schmidt External Behavior of System Sort A “line” is a sequence of characters terminated by a newline default ordering is lexicographic by bytes in machine collating sequence ( e.g. , ASCII) The ordering is affected globally by the following options: – Ignore case (-i ) – Sort numerically (-n ) – Sort in reverse (-r ) – Begin sorting at a specified field (-f ) – Begin sorting at a specified column (-c ) Note, our program need not sort files larger than main memory Vanderbilt University 3 OO Pattern Examples Douglas C. Schmidt High-level Forces Solution should be both time and space efficient – e.g. , must use appropriate algorithms and data structures – Efficient I/O and memory management are particularly important – Our solution uses minimal dynamic binding (to avoid unnecessary overhead) Solution should leverage reusable components – e.g. , iostreams, Array and Stack classes, etc. Solution should yield reusable components – e.g. , efficient input classes, generic sort routines, etc. Vanderbilt University 4 OO Pattern Examples Douglas C. Schmidt Top-level Algorithmic View of the Solution Note the use of existing C++ mechanisms like I/O streams // Reusable function: // template <class ARRAY> void sort (ARRAY &a); int main (int argc, char *argv[]) { parse_args (argc, argv); Input_Array input; cin >> input; sort (input); cout << input; } Vanderbilt University 5 OO Pattern Examples Douglas C. Schmidt Top-level Algorithmic View of the Solution (cont’d) Avoid the grand mistake of using top-level algorithmic view to structure the design . . . – Structure the design to resolve the forces! – Don’t focus on algorithms or data, but instead look at the problem, its participants, and their interactions!...
View Full Document

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 26

pattern-examples4 - Object-Oriented Design Case Studies...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online