Conclusion
In the last demo, you updated ContactCard
to use aggregation for the related contacts and link them together using a unique identifier. You also moved the responsibility of creating the two-way relationship and the implementation details of how to create the relationship to a function inside the structure.
Here are the things you learned in this lesson:
- Composition and Aggregation are two different tools that help you define how the building blocks of your models or the parts of your system come together.
- They’re meant to work together and complement each other. They are not mutually exclusive.
- Which one to use depends on what makes the most sense for your system. That choice might not necessarily make sense for another system.
- Composition means the object fully owns the composing parts. If you delete the main object from memory, all the parts used with Composition will also be deleted.
- Aggregation means the objects are separate from the main object but are linked to it. If you delete the main object, the other smaller objects can still live and function separately.
In the next lesson, you’ll learn about classes and what it means for classes to have static members and static methods. These are advanced concepts in object-oriented programming that will improve how you build your apps, allowing you to deliver more functionality with less effort.