• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Having some trouble with a complex class aggregation

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 192
9
Scala IntelliJ IDE Netbeans IDE Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic