(2): Project 1
[ project1.html ]
is due at start of this class.
Quiz 1
There will be a Quiz on first 5 chapters and/or your project
(Not on today's reading and class). It is worth a maximum of
30 points. The structure is:
I have several pages of information on the Unified Modeling Language.
The quick Guide
[ uml0.html ]
is a useful starting point.
Demo -- diagrams of given C++ code
Instructor will draw a class diagram of
class Pair
{
public:
double first;
double second;
Pair( double x, double y){ first=x; second=y;}
};[ 04pair.cpp ] and an object diagram of [ 04testPair.cpp ] (a test program).
Here is a class definition in C++, draw a class diagram in the UML that models it:
class Triangle
{
public:
Pair vertex1;
Pair vertex2;
Pair vertex3;
Triangle(Pair v1, Pair v2, Pair v3) { vertex1=v1; vertex2=v2; vertex3=v3 }
};
Here
[ 04ex.gif ]
is one of my answers to this problem.
Questions
Example: my watch.
In C++ the operations that an object can do come from it's class.
Example: My watch is a Digital Watch. A Digital Watch is a special
kind of Watch.
What does Object-Oriented mean?
An object-oriented program is designed so that it reflects
the world with which it is concerned. The real world is
(mainly) made of objects that respond in more or less predictable
ways to events. Real world objects belong to classes that describe
them. The object "dick", for example, is an instance
or object of class "People". An object oriented program has similar
objects an classes. The behaviors inside the computer simulate the real world
consequences of events.
In the real world there are three relationships:
| Relation | Means | Example | UML |
|---|---|---|---|
| ISA | is a special kind of | Male is a Person | Male---|>Person |
| HAS A | has a | A Person has two Legs | Person <>-->Legs |
| KNOWS | can access | A Bank knows its Customers | Bank--->Customer |
It also impresses people in job interviews.
When is OO a waste of time?
Only when the problem is small and simple: for example
a routine to evaluate a square root is best done by
the old fashioned structured methods.
How will we use objects?
From now on think of ALL data as objects.
Learn to start solving a problem by listing the classes of object and how they are related -- in the real world.
Allocate operations to the classes in the problem so that they do
useful work.
When to use inheritance?
Use inheritance/ generalization when one class
of object "is a special kind of" another kind:
Car is a special kind of vehicle, for example.
More in meeting 7 and chapter 9.
How does an operation act on an object?
Suppose I have a Cat called "Stranger", what happens
when I stroke it?
Cat stranger;
...
cout << stranger.stroke();Answer: output "purr".
The compiler looks at the type of object stranger is and finds out that
stranger is a Cat. It, therefore replaces stranger.stroke(); by
a call to a function stroke in class Cat -- with the variable this
pointing at stranger. The operations inside this function stroke all
refer to the data in the object stranger. As a rule you find the
data in the object and the function in the class. So all objects share the
"member" functions.
When will use the UML?
Throughout this class, and also in CSCI320, CSCI330, CSCI350,......CSCI455,....
and your job.
What are generic program units in C++?
The are called templates. We will cover them in meetings 17 and 18
(Chapter 14).
. . . . . . . . . ( end of section CSci202 Computer Science II, Session 04, Objects and the UML) <<Contents | End>>
(Next): Classes in C++:
[ 05.html ]
Abreviations