What's the difference between composition and aggregation
What do the expressions “is” and “has” mean in terms of OOP principles?
"Is" implies inheritance. "Has" means an association (aggregation or composition).
What's the difference between composition and aggregation?
Association denotes a relationship between objects. Composition and aggregation are special cases of the “part-whole” association.
Aggregation assumes that objects are connected in a "part-of" relationship. Composition is a stricter variant of aggregation. In addition to the “part-of” requirement, the condition is imposed that the “part” instance can only be included in one whole (or not included anywhere), while in the case of aggregation, the “part” instance can be included in several ones.
For example, a book consists of pages, and we cannot rip a page out of a book and insert it into another book. Pages are clearly linked to a specific book, so this is composition. At the same time, we can take and transfer a book from one library to another - this is already an aggregation.
Read also:
- Basic principles of OOP
- What is "encapsulation"
- What is "inheritance" in OOP
- What is "polymorphism" in OOP
- What are the advantages and disadvantages of an object-oriented approach to programming
Comments
Post a Comment