Jump to content
  • Advertisement
Sign in to follow this  
EvilWeebl

[java] Newbie question about multiple inheritance/delegation/interfaces

This topic is 3212 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people just learning java and was wondering if I could get some help on this because I just cant wrap my head around this 'no multiple inheritance' stuff. So I get that a class can only inherit one class but can implement multiple interfaces. But I cant understand how to get this into code. Heres a task iv been sent and have been provided this diagram to show how multiple inheritance can be achieved: UML diagram The objective of this task is to use java interfaces and delegation (composition) in order to simulate multiple inheritance 1- Objective: you will define the following class hierarchy: – Student, with a Name with a Unumber – Employee, with a salary – EmployedStudent, a person with a Unumber and a salary Unumber and salary are private data, instanciated by the constructors. You will define getter methods. 2- The Trick: Implement this hierarchy, using classes and an additional interface (or several additional classes and interfaces), so that the code in EmployedStudent members is reduced to a minimum of calls to the other classes methods. Please someone show me in detail as to what im doing here! In the image is 'superclass' the employee and 'delegate' the student with 'myclass' being the EmployedStudent? Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Please someone show me in detail as to what im doing here!


How about you first show in detail what you've tried?

Quote:
In the image is 'superclass' the employee and 'delegate' the student with 'myclass' being the EmployedStudent?


The line with diamond means "has a". How could that be useful here?

Share this post


Link to post
Share on other sites
Iv tried multiple things, each ends up in the recycle bin. I could probably figure out the coding if I just understood the structure.

Ok well would it work if the 'superclass' was the employee, the 'myclass' was student and the 'delegate' was EmployedSteudent? If im right that would mean 'myclass' contains the same methods as it parent as well as defining the implemented method from the interface and then the 'delegate' class contains an instance of that allowing it to call methods from both employee and student. If im wrong shoot me down but can I please get a solution this time.

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilWeebl
Ok well would it work if the 'superclass' was the employee, the 'myclass' was student and the 'delegate' was EmployedSteudent?
I'd give you a D or E grade, how can you think a generic Student can be an Employee? Only an EmployedStudent is.

Since it seems homework, only some hints:

1) Any solution that isn't perfectly symmetrical between Student and Employee is flawed.
2) Any sort of composition or delegation you devise can only have the "person" classes and interfaces of the domain model as the owner (a person consists of person components), not as a part of another person.
3) The interesting part of the exercise is using delegation to minimize redundancy between EmployedStudent and other Student and Employee implementations; if EmployedStudent were the only one, no other class could be redundant with it.

Share this post


Link to post
Share on other sites
Dude im 23 I dont get homework anymore, this is self learning and why is it that nobody can give me a straight answer when all this is meant to be beginner stuff? Please please please no more hints and tips, I really just want an answer so I can study the pattern and how it works and then use that knowledge to benefit me in future endeavours. No disrespect intended its just this is really bugging me now im sure its such a stupid little thing but a week is too long to spend on something like this without progression.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!