Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having some trouble with a complex class aggregation

 
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.
 
Simon Roberts
Author
Ranch Hand
Posts: 170
7
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually a pretty big question you asked there. The short, and quite possibly not terribly helpful answer is: Use the super() keyword.

e.g.



I'm not sure if that's enough to get you going...

Hope it helps,
Cheers,
Simon
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
paul c. kim wrote: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.

Let's see if I can understand your problem correctly.

So we have a class which has already 2 instance members of different classes. Something like this

And then you want to use the Body class as an aggregate in another class (e.g. Person) that shares the same instances as the Body class. Correct? If it is, I see 2 alternatives:

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic