Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question
- Why do people over the internet still calls aggregation as composition.
- [Both are has-a relationship but stills huge difference are there]
- public class ParkingLot {
- List<ExitPanel> exitPanels;
- public ParkingLot() {
- this.exitPanels = new ArrayList<>();
- }
- public void addExitPanel(ExitPanel panel) { exitPanels.add(panel); }
- public List<ExitPanel> getExitPanels() { return exitPanels; }
- }
- Will you call above as Aggregation or Composition ?
- [=] I will call it Aggregation because exitPanels are created in driver's class and just their ref is passed. The lifecycle is not controlled by the ParkingLot.
- Trade-Offs
- Q ] what trade-offs you take when deciding between aggregation and composition. Aggregation definitely comes with scalability as the lifecycle is not controlled by a specific class and can be reused.But If Lifecycle is not controlled by someone that means we have to take care of it which is an overhead(maintainabilty).
- Loose and Tight Coupling
- Q ] Is one (Aggregation) always loosely couple and the other (composition) is tightly coupled, or are there any exceptions.
Advertisement
Add Comment
Please, Sign In to add comment