Instruction 1
According to the Oxford Pocket Dictionary of Current English, Composition
means “the nature of something’s ingredients or constituents; the way in which a whole or mixture is made up”. You can say a house is composed of walls and floors, or a letter is composed of words. The composing item is part of the whole, not separated from it.
But Aggregation
means “the formation of a number of things into a cluster”. It’s a bunch of things grouped together to form something else — like a sports team is a group of players, or a company has employees. Each of the units can exist individually, but together they form the entity.
To help you understand it in software engineering terms: Composition means that the main object owns the items that its composed from. If you delete the main object, all the items inside it get deleted. On the other hand, with Aggregation, when you delete the main object, the smaller ones can still exist.
For example, a text file is composed of characters. If you delete this text file, you’ll delete all the characters that are contained within that file, but you don’t lose the fonts you used in that text file. The file is indeed composed of characters, but it also references the fonts you have on your computer.
Using composition doesn’t mean you can’t use aggregation for something else or vice versa. They’re meant to complement each other to help you define your objects in a meaningful way. With the example of the text file, both are used in different parts where it makes the most sense.
It’s also not a rule of thumb that once you define something by aggregation, you must always define it that way, even in different apps with different requirements. If the smaller object doesn’t make sense on its own in one app, then you don’t need to use aggregation in that app. The same goes for Composition.
For example, say your app defines companies and employees. It usually makes sense to use aggregation to define the employees in this company. They can move from one company to the other. But if your app doesn’t deal with the employee as a separate entity, and just stores their work phone numbers, it would make sense to delete the employee information when you delete the company. In that case, you could use Composition.
The key point for you is to understand how your app will interact with different objects so you can define the relationships and ownership between them properly, without overcomplicating anything.