Guest User

Untitled

a guest
Dec 20th, 2024
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Question
  2. Why do people over the internet still calls aggregation as composition.
  3. [Both are has-a relationship but stills huge difference are there]
  4.  
  5. public class ParkingLot {
  6. List<ExitPanel> exitPanels;
  7.  
  8. public ParkingLot() {
  9. this.exitPanels = new ArrayList<>();
  10. }
  11.  
  12. public void addExitPanel(ExitPanel panel) { exitPanels.add(panel); }
  13.  
  14. public List<ExitPanel> getExitPanels() { return exitPanels; }
  15. }
  16.  
  17. Will you call above as Aggregation or Composition ?
  18. [=] 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.
  19.  
  20. Trade-Offs
  21. 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).
  22.  
  23. Loose and Tight Coupling
  24. Q ] Is one (Aggregation) always loosely couple and the other (composition) is tightly coupled, or are there any exceptions.
  25.  
Advertisement
Add Comment
Please, Sign In to add comment