• Post Reply Bookmark Topic Watch Topic
  • New Topic

layered aggregation?  RSS feed

 
paul c. kim
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have learned in the Java book on class aggregation, and Aggregation is when an instance of a class is in another class. However, what if I needed my class that already has two instances of different classes and I want to aggregate that class into another class that shares the same instances as the class that I want to aggregate? I have tried using inheritance which is beyond the chapter that the problem was addressed, however, I don't know how to call the superclass constructor when the constructor of superclass and subclass accept objects as args.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aggregation and Inheritance are mutually exclusive, I believe. If the Class Car HAS-A wheel, use aggregation. If the Ford IS-A car, then use inheritance.

In a subclass constructor, you can call the superclass's constructor like this:

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing in objects would look like this:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!