- STL makes frequent use of logical the operators
=, !=, <, <=, >, >=
- so it defines !=, <=, >, >= based on = and <
Pair - we often need pairs of values, so it defines:
template <class T1, class T2>
struct pair cfw_
There are two types of static model in object-oriented design
client and inheritance relations
varying levels of detail about each class
varying levels of detail about class relations
Class diagrams showing
STL map example
/ Demonstrating an STL map.
#include <cstring.h> / should be first
using namespace std;
map<string, long, less<string> > directory;
directory["Bogart"] = 1234567;
Poly (many) - morph (form) - ism (action)
". ability to define program entities that may take more than one form ."
Actions take many forms
- a child class may implement an operation differently to it's parent class
- if the parent has many c
Here are a few other things to consider .
Small core operation set
Accessors vs mutators
Errors vs exceptions
Call / return value vs reference
"Once in a header file far far away, there was a strange compil
Obviously class implementations must be correct as in it meets its requirements;
what else do we mean by correctness?
A class must provide a logically complete set of services
stack: push, pop, isEmpty, isFull
account: deposit, withdr
Kinds of Exception
An exception has occured when
Logical errors are discovered by the program
- eg. When we have removed all the items we added to a list, we expect that it will
- eg. When we have created an array, we expect that all subscripts u
Pointer-like objects that can be used like a cursor;
the glue between the algorithms and the containers
The algorithms use iterators to access the containers
Forward iterator (input and output) capabilties
= != * +
Bidirectional iterator capabil
". ability to define parameterized modules ."
Valuable when the algorithm is the same but the typesused may change
May be used with functions, procedures, or classes
Another gain in programmer productivity: we only need to write the algorithm o
"There are no new ideas in computing"
"The one constant in life is change itself"
Inheritance allows us to use what already exists and incorporate changes
Inheritance also allows us to extract commonality from classes into a single
Detecting Logical Exceptions and Retrying
Logical exceptions are detected by evaluating logical expressions in our code and deciding
that some "impossible" condition is true
Langauge facility is invoked to raise or throw an exception
At an earlier point i