Think you know the basic C++ code patterns implementing the five UML class relationships? Try this simple test.
class A
{
};
class B : public A
{
};Inheritancelook for the string ": public" followed by a class name:: public super_class_name |
class B
{
A* a;
};
class A
{
B* b;
};
Associationlook for pointer member variables in both classes:A* a; B* b; |
class B
{
};
class A
{
B* b;
};
Aggregationlook for a single member pointer variable in one (the whole) class:B* b; |
class B
{
};
class A
{
B b;
};
Compositionlook for a non-pointer member variable in one (the whole) class:B b; |
class A
{
public:
T func1(B b) {...}
T func2(B* b) {...}
T func3(B& b) {...}
};
Dependencylook for functions with a class-type parameter |
class A
{
T func4()
{
B b;
b.function();
}
};Dependencylook for a function with a local class-type variable |