YALE UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE
CPSC 427a: Object-Oriented Programming | Handout #10 | |
Professor M. J. Fischer | November 27, 2011 | |
Study Guide to Exam 2
This exam covers the entire course, but emphasis will be on topics covered since exam 1 (see Study Guide to Exam 1). You are reponsible for the contents of lectures 1–21, 22a, 22b, and as much of lectures 23a and 23b as we are able to cover in class on November 29. You are also responsible for the corresponding class demos, concepts used in the problem sets, and the entire textbook (Chapters 1–18) except for the following chapeters and sections:
Below is an index to the lecture notes. It lists all of the sections, subsections, and slide titles from all of the lectures.
∙ Where to find information
∙ Course mechanics
∙ Topics to be Covered
∙ Course goals - practical
∙ Course goals - conceptual
∙ Two views of programming
∙ Problem solving
∙ Software Construction
∙ Programming in the large
∙ Three commandments for this course
∙ Can is not the same as should!
∙ Why did C need a ++?
∙ C++ was Designed for Modeling
∙ General properties of C++
∙ C++ Extends C
∙ Some Extensions in C++
∙ Tools
∙ Recommended IDE’s
∙ Generic Insertion Sort
∙ C version
ee code demo02
∙ C++ version
ee code demo02
∙ C++ version
ee code demo03
∙ dataPack.hpp
∙ class DataPack
∙ Class elements
∙ Inline functions
∙ Visibility
∙ Constructor
∙ Constructor
∙ Destructor
∙ Destructor
∙ dataPack.cpp
∙ File I/O
∙ main.cpp
∙ Manual compiling and linking
∙ Makefile
∙ Integrated Development Environment (e.g., Eclipse)
∙ Integrated Development Environment (e.g., Eclipse)
∙ Integrated Development Environment (e.g., Eclipse)
∙ Toolset to use for course work
∙ Working remotely
∙ 1. Replicate the Zoo environment on your own machine
∙ 2. Remote login to the Zoo
∙ 3. Set up a virtual Zoo desktop on your machine
∙ Homework submission
∙ A brief course review to date
∙ How to use the textbook
∙ Operator extensions
∙ Adding new methods
∙ Two kinds of functions
∙ An ambiguity with operator extensions
∙ Operator call example: Top-level function
∙ Operator call example: Member function
∙ Back to PS1
∙ Opening and closing streams
∙ Reading data
∙ Writing data
∙ Manipulators
∙ End of file and error handling
∙ Call by value
∙ Call by pointer
∙ Call by reference
∙ I/O uses reference parameters
∙ How should one choose the parameter type?
∙ Sending data to a function: call by value
∙ Sending data to a function: call by reference or pointer
∙ Receiving data from a function
∙ The implicit argument
∙ this
∙ L-values and R-values
∙ Simple variable declaration
∙ Simple assignment
∙ Automatic dereferencing
∙ Pointer values
∙ Pointer creation
∙ Pointer variables
∙ Pointer assignment
∙ Following a pointer
∙ Pointer example
∙ Pointer declaration syntax
∙ Reference types
∙ Reference declarators
∙ Use of named references
∙ Reference parameters
∙ Reference return values
∙ Custom subscripting
∙ Constant references
∙ Comparison of reference and pointer
∙ Handling data errors and end of file
∙ How to write a test program
∙ Classes, visibility, functions, inline
∙ Bar Graph Demo
∙ Bar graph sample input and output
∙ Bar graph data structure
∙ UML Diagram
∙ Notes: graph.hpp
∙ Notes: graph.cpp
∙ Notes: row.hpp
∙ Notes: row.cpp
∙ Nested classes: rowNest.hpp
∙ Variables and storage
∙ Example of a variable
∙ Properties of variables
∙ Storage classes
∙ Assignment and copying
∙ Static data members
∙ Static function members
∙ Five common kinds of failures
∙ Optional parameters
∙ const
∙ const implicit argument
∙ Operator extensions
∙ What is a class?
∙ Class relationships
∙ What is derivation?
∙ Instances
∙ Some uses of derivation
∙ Example: Parallelogram
∙ Example: Rectangle
∙ Example: Square
∙ Notes on Square
∙ Structure of an object
∙ Example of object of a derived class
∙ Referencing a composed object
∙ Referencing a base object
∙ Initializing an object
∙ Construction rules
∙ Destruction rules
∙ Constructor ctors
∙ Initialization ctors
∙ Initialization not same as assignment
∙ Copy constructors
∙ Polymorphism and Type Hierarchies
∙ Polymorphic pointers
∙ Virtual functions
∙ Unions and type tags
∙ Virtual destructors
∙ Uses of polymorphism
∙ Multiple representations
∙ Heterogeneous containers
∙ Run-time variability
∙ Pure virtual functions
∙ Abstract classes
∙ Private derivation (default)
∙ Private derivation example
∙ Public derivation
∙ Public derivation example
∙ The protected keyword
∙ Protected derivation
∙ Privacy summary
∙ Surprising example 1
∙ Surprising example 2: contrast the following
∙ Surprising example 3
∙ Names, Members, and Contexts
∙ Declaration and reference contexts
∙ Declaration context example
∙ Reference context example
∙ Inside and outside class references
∙ Examples
∙ Inherited names
∙ Inheritance example
∙ Inaccessible base class
∙ What is a Class: Syntax
∙ Class Relationships
∙ Class Relationship Between Two Classes
∙ Class B appears in Definition of Class A
∙ B as Data Members in A
∙ B as Data Members in A
∙ Creation and Deletion
∙ Example: BarGraph Class Interaction
∙ Association Relationship
∙ Accessing B in A’s methods
∙ “Law” of Consistency/Encapsulation
∙ Limiting coupling between classes
∙ “Law” of Demeter
∙ Goals of OO Programming
∙ Insertion sort example
∙ Compiling and linking
∙ Compiler errors
∙ Tool set
∙ C++ goodies
∙ Stream I/O
∙ Functions and methods
∙ Variables and data
∙ BarGraph demo
∙ More on variables
∙ Five kinds of memory errors
∙ C++ bells and whistles
∙ Derivation
∙ Polymorphic derivation
∙ Visibility rules
∙ Explicit privacy attributes
∙ Implicit privacy attributes
∙ Implicit privacy chart
∙ Summary
∙ A retrospective look at PS2
∙ Testing
∙ Low-level details
∙ Example picky detail
∙ Efficient use of resources
∙ Efficiency measurement
∙ How to measure run time of a program
∙ High resolution clocks
∙ Measuring time in real systems
∙ Realtime measurements
∙ HirezTime class
∙ Versions of HirezTime
∙ HirezTime structure
∙ Printing a HirezTime number
∙ StopWatch class
∙ Casting a StopWatch to a HirezTime
∙ Why it works
∙ Hangman game
∙ Modularizing timing tests
∙ Structure of class Tester
∙ Objective ??
∙ Objective ??
∙ Objective ??
∙ Objective ??
∙ Member function pointers
∙ Declaring member function pointers
∙ Using typedef with member function pointers
∙ Creating member function pointers
∙ Using member function pointers
∙ Hangman game
∙ Overall design
∙ Use cases
∙ Code structure: Model
∙ Code structure: Viewer and controller
∙ Class Game
∙ Storage management
∙ String store
∙ Refactored hangman game
∙ Flex arrays
∙ Flex array implementation issues
∙ String store limitation
∙ Refactoring Board class
∙ Template overview
∙ Template functions
∙ Specialization
∙ Template classes
∙ Compilation issues
∙ Template parameters
∙ Using template classes
∙ A bit of history
∙ Containers
∙ Common container operations
∙ vector<T>
∙ Iterators
∙ Iterator example
∙ Using iterator inside a class
∙ Using subscripts and size()
∙ Algorithms
∙ STL sort algorithm
∙ Reverse sort example
∙ Reverse sort example (cont.)
∙ pair<T1, T2>
∙ map<Key,Val>
∙ Using a map<Key,Val>
∙ Copying from one container to another
∙ Copying from map to vector of pairs
∙ string class
∙ Casts in C
∙ Different kinds of casts
∙ C++ casts
∙ Explicit cast syntax
∙ Implicit casts
∙ Ambiguity
∙ explicit keyword
∙ How to define operator extensions
∙ Other special cases
∙ Virtual virtue
∙ Main virtue
∙ Using polymorphism
∙ Interface file
∙ Class Linear
∙ Example: Stack
∙ Example: Queue
∙ Class structure
∙ C++ features
∙ #include structure
∙ Exceptions
∙ Exception handling
∙ C-style solution using status returns
∙ C++ exception mechanism
∙ Throwing an exception
∙ Catching an exception
∙ What kind of object should an exception throw?
∙ Standard exception class
∙ Catching standard exceptions
∙ Deriving your own exception classes from std::exception
∙ Multiple catch blocks
∙ Rethrow
∙ A subtle fact about rethrow
∙ Example
∙ Results
∙ Throw restrictions
∙ Uncaught exceptions: Ariane 5
∙ Uncaught exceptions: Ariane 5 (cont.)
∙ Termination
∙ Demo 20a-Multiple
∙ Ordered base class
∙ Container base class
∙ class Item
∙ class Linear
∙ class PQueue
∙ What is multiple inheritance
∙ Object structure
∙ Diamond pattern
∙ Tightly coupled classes
∙ Example: List and Cell
∙ Circularity with #include
∙ What happens?
∙ Resolving circular dependencies
∙ Using templates with polymorphic derivation
∙ Container class hierarchy
∙ Item class hierarchy
∙ Ordered template class
∙ Alternative Ordered interfaces
∙ Overview of linear container example
∙ Differences in functionality
∙ Class structure
∙ Template structure
∙ Further extensions
∙ Two problems
∙ Defining KeyType
∙ Constructing the data elements
∙ 21a-Multiple-template
∙ Storage management
∙ Derivation from STL containers
∙ Replacing authority with understanding
∙ Two kinds of derivation
∙ How are they the same?
∙ What is simple derivation good for?
∙ What are the problems with simple derivation?
∙ What is polymorphic derivation good for?
∙ What are the problems of polymorphic derivation?
∙ Contrasts between simple and polymorphic derivation
∙ Containment as an alternative to simple derivation
∙ Argument for containment
∙ STL container as a base class
∙ Can I turn an STL container into a polymorphic base class?
∙ A polymorphic base class
∙ Dynamic cast
∙ General OO principles
∙ What is a design pattern?
∙ Adaptor pattern
∙ Adaptor diagram
∙ Indirection
∙ Proxy pattern
∙ Polymorphism pattern
∙ Polymorphism diagram
∙ Controller
∙ Three kinds of controllers
∙ Bridge pattern
∙ Bridge diagram
∙ Subject-Observer or Publish-Subscribe: problem
∙ Subject-Observer or Publish-Subscribe: pattern
∙ Subject-Observer or Publish-Subscribe: diagram
∙ Singleton pattern
∙ StringStore example
∙ The Waterfall Software Process
∙ Why a Pure Waterfall Process is Usually Not Practical
∙ The Spiral Process
∙ Advantage of OO Design
∙ Aspect of Reusability
∙ Making a Class Re-usable
∙ Reducing Dependency Among Classes
∙ Aspect of Flexibility
∙ Some Techniques to Achieve Flexibility
∙ Roadmap
∙ What is a Design Pattern
∙ UML/OMT Notation
∙ User Interfaces
∙ Interfaces for C++
∙ Overall Structure of a GUI
∙ Concurrency and Events
∙ Event Loop
∙ A GUI event structure
∙ Interface between user and system code
∙ Binding system calls to user functions
∙ Polymorphic binding
∙ Binding through callback registration
∙ Callback using function pointers: GUI side
∙ Callback using function pointer: User side
∙ Type safety
∙ Signals and slots
∙ Structure of gtkmm
∙ Compiling a gtkmm program
∙ Linking a gtkmm program
∙ Using a GUI
∙ Example: clock
∙ Main program
∙ Initial Design
∙ Design Change: add fly()
∙ Problem
∙ Anticipating Changes
∙ Handling Varying Behaviors
∙ Design
∙ Programming to implementation vs interface/supertype
∙ Implementation
∙ Exercise: Add rocket-powered flying?
∙ Exercise
∙ Summary: Design Principles
∙ KitchenViewer Example
∙ Selecting Antique Style
∙ KitchenViewer Using Standard Inheritance
∙ The Abstract Factory Idea
∙ Abstract Factory Design Pattern Applied to KitchenViewer
∙ Concrete and Abstract Layers
∙ Abstract Factory Application Sequence Diagram
∙ Potential use of this Design Pattern?
∙ Problem
∙ Starbuzz UML
∙ Attempt 1
∙ Potential Changes
∙ Design idea
∙ Design approach 1
∙ Decoration Delegation Process
∙ Decorator Class Model
∙ Sequence Diagram for Decorator
∙ Decoration Features
∙ Exercise: different sizes for beverages
∙ Example: Weather-O-Rama
∙ Weather-O-Rama
∙ Weather-O-Rama Interface
∙ First Implementation
∙ Observer Design Pattern
∙ How does Observer apply these design principles?
∙ Discussion