Composition is one part of another class, it has the same life time
and exclusive ownership such as People and Heart class.
Aggregation is a specialized form of Association where all objectshave their own life time, and hasownership and one class can’t
belongs to another class simultaneously. Such as Teacher and School.
Association is a relationship where all objects have their own lifetime and there is no ownership. Let’s take an example of Teacher
and Student. Both can create and delete independently.
Dependency is weaker relationship. And Class just use another class as
method parameter or method return. No member in another Class.
Such as Teacher and Computer. In GOF, It use dotted line to represent
A class create B class.
Basic Ideas:
Don’t overdesign, Don’t use design pattern just because itis here. Just know some basic design pattern, and follow your real
problem, make design fit you problem first, If something changes
in the future, you can refactory it later.
Main question in design is: How many classes do you need?
Interface of each classes? relationship of Classes(is-a, has-a, and
association. )
When you have all these classes from your practical
problem(application), then you need to think three questions. 1)
If it’s high cohension 2) if it’s loose coupling 3) if there is future
change.
Then you should use design pattern to design your class again.
Inheritance has three level knowledges.
The basic knowledge, manager is a person, apple is a fruit,
and bla bla bla.
Reused code, pure virtual, virtual, and non virtual, Such as
introduced in inheritance section.
Isolate change between Client and Implement. That is
the highest level in design pattern.