I don’t understand the concept of association in C++
This is my code examples:
Association: Object A knows about object B. Class A depends
from B but does NOT consist of it
Car
{
???
};
Agregation don’t manages life cycle
Car
{
Engine* engine;
Car(Engine& eng) {
engine = eng;
}
};
Composition manages life cycle
Car
{
Engine* engine;
Car() {
engine = new Engine();
}
~Car() {
delete engine;
engine = nullptr;
}
};
I saw such an example
Car
{
Engine* engine;
};
but I believe that this is not an association because it violates the principle Class A depends
from B but does NOT consist of it
8