Real life example
Ghar aur kamre (composition): ghar gira to kamre khatam. Team aur player (aggregation): team khatam, player zinda.
Industry example
Order aur OrderItem composition hai. Hospital aur Doctor aggregation. Doctor aur Patient association.
C++ code
class Engine {};
class Car { Engine e; }; // composition
class Team { Player* p; }; // aggregation
What happens when it runs
Car delete = Engine bhi delete Team delete = Player zinda
Run the full program in the compiler Interactive version
Quiz
Composition me parent khatam hone par part ka kya hota hai?
Composition me part parent ke saath marta hai.
Try it yourself
Write one example of Association, Composition, Aggregation from your own home, school or work. Then change the program in the compiler and run it again.
All 12 OOP lectures
- Lecture 1: Introduction aur Objects
- Lecture 2: Encapsulation aur Interface
- Lecture 3: Abstraction, Class, Inheritance
- Lecture 4: Inheritance ke Concepts
- Lecture 5: Association, Composition, Aggregation
- Lecture 6: Polymorphism
- Lecture 7: C++ me Class
- Lecture 8: Constructor
- Lecture 9: Copy Constructor, Destructor, this
- Lecture 10: this Pointer aur const Functions
- Lecture 11: const, Initializer List, static
- Lecture 12: static Functions aur Array of Objects
START WELL TO END WELL