Object-oriented programs typically consist of many objects bound together to form a complete program. The binding enables objects to communicate, and through this communication, they cooperate to solve the problem for which we wrote the program. The Unified Modeling Language (UML) recognizes five different relationships that bind objects together. C++ is not limited to binding objects with the UML relationships, nor is the UML necessary for writing object-oriented programs. Nevertheless, the UML provides a convenient way of identifying and communicating object-oriented concepts, making it a helpful tool for learning how to create multi-class programs. Chapter 10 demonstrates how to build programs consisting of multiple objects instantiated from multiple classes, and how to use the binding relationships to solve programming problems.
Please focus on the following as you study Chapter 10:
| Inheritance | Composition | Aggregation | Dependency | |
|---|---|---|---|---|
class Foo
{
...
};
|
class Bar : public Foo
{
...
};
|
class Bar
{
private:
Foo f;
}; |
class Bar
{
private:
Foo* f;
}; |
class Bar
{
public:
void function(Foo f) {...}
}; |
| Association | |
|---|---|
class Foo; // forward declaration (pointer only)
class Bar
{
private:
Foo* f;
}; |
class Bar; // forward declaration (pointer only)
class Foo
{
private:
Bar* b;
}; |