This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes A good question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "A good question" Watch "A good question" New topic
Author

A good question

Erum Arif
Greenhorn

Joined: Aug 21, 2001
Posts: 3
Q) A tennis coach is a student and a trainer? How could we represent it in a diagram?
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
You could make Coach as an abstract class which has a method getIndividual(), which returns Coach.This method would be implemented by the Student and Trainer class, which inherits from class Coach.So we can use the Polymorphism pattern here.
Comments,please
-- Sandeep


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Adrian Ferreira
Ranch Hand

Joined: May 29, 2000
Posts: 118
Hello,
Honestly, I would represent as Student interface, another Trainer interface and a Coach class that implements both Student and Trainer.
Sorry if it does not meke much sense, I am completly new on this topic.
Adrian
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Adrian,
It depends on what you want.If you want, the "Coach" to be of the type of "Student" and "Trainer" then having "Student" and "Trainer" as interfaces and implementing them as a "Coach" class makes sense.This would mean "Coach as a type of Student and Trainer".
However, if you want the "Coach" to be either a "Student" or "Trainer" then making "Coach" as an abstract class is a better solution.
Hope this helps,
Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited August 21, 2001).]
Adrian Ferreira
Ranch Hand

Joined: May 29, 2000
Posts: 118
Desai,
I agree, that is true.
Thanks for your explanation.
Adrian
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Another possibility would be to define a Role interface, let Student and Trainer implement Role, and let Coach have an one to many association to Role.
As others said, it heavily depends on the wider context.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
ted oniger
Greenhorn

Joined: Aug 05, 2001
Posts: 16
Hello,
I am following the discussion but I am a bit confused regarding the functions of the coach. Are we talking about just two functions like a person (who is the coach) can be a student and a trainer, or three functions: a person can be a coach, a student or a trainer?
The reason I ask this is if we make the coach as an abstract class and if the coach is a another function, how can we make an instance of that class.
Well, I don't know, maybe I am speaking out of context. Any clarification, please.
Ted
Adrian Ferreira
Ranch Hand

Joined: May 29, 2000
Posts: 118
Ted,
I think you understand. This discussion became more generic.
In some models described here, like that using two interfaces, you can only have one instance (class Coach) that works like Trainer and Student since Interface as well as abstract class can not be instanciated. Other model suggests that your Coach object can be either a Student or a Trainer as explained before.
Actually, the first question asks for the "and", not "or" condition.
A tennis coach is a student and a trainer?

Adrian
zaeem masood ashar
Ranch Hand

Joined: Mar 17, 2001
Posts: 54
Hi
Having an abstract "Coach" class beats me!!!
Sorry! i am also new to modeling
so would it be like..........

what good is the getIndividual() method for?
How do i return a Coach(abstract)class object?
thanks


SCJP2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A good question