File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A good question

 
Erum Arif
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q) A tennis coach is a student and a trainer? How could we represent it in a diagram?
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adrian Ferreira
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Desai,
I agree, that is true.
Thanks for your explanation.
Adrian
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ted oniger
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic