Java Forum / General / August 2007
OO Design: Who can do what?
antonyliu2002@yahoo.com - 10 Aug 2007 16:21 GMT OO Design continued.
When we try to design a class, we try to think about what the objects of the class can do, like quite many OO programming books say.
Let's suppose that we are gonna design a ProjectManager class and a Project class.
Well, what can a ProjectManager do? I think s/he can createNewProject, deleteProject, assignFundToProject, requestFund, deleteFund, editProject, viewProjectList, etc.
What can a Project do? I don't know except some getter setter methods. The reason I don't know about it is because a project is not animate, thus I am not sure what action it can perform.
So, naturally, I put those named methods above (createNewProject, deleteProject, assignFundToProject, etc.) into the ProjectManager class, because I think those are the things that a ProjectManager can do.
But my colleague told me that those methods should really go into the Project class. I assume that my colleague is right, because I do not have much experience in OO design. But, then,
1. Why does it make more sense to put those methods in the Project class than in the ProjectManager class, giving the instructions of OO programming textbooks?
2. If we move those methods into the Project class, then what can a ProjectManager do?
I want to be a good OO designer, so, please do share your wisdom about this. Thanks.
Manivannan Palanichamy - 10 Aug 2007 17:46 GMT On Aug 10, 8:21 pm, "antonyliu2...@yahoo.com" <antonyliu2...@yahoo.com> wrote:
> OO Design continued. > [quoted text clipped - 30 lines] > I want to be a good OO designer, so, please do share your wisdom about > this. Thanks. Your first design is correct. the design confusion is because of unclear requirements. you should start from UseCase diagram, and then will come to know what each Actor got to do.
Anyway. In this case, the Project will be a a resource class. Like a value object. So, obviously it will have only getters & setters.
I would agree with the following design:
class Project { get/setName(); get/setReleaseDate(); get/setTeams(); get/setProjectManager(); }
class ProjectManager { Project createNewProject(); deleteProject(Project project); assignFundToProject(Project project, Fund fund); }
-- Manivannan.Palanichamy (@) Oracle.com http://mani.gw.googlepages.com/index.html
antonyliu2002@yahoo.com - 10 Aug 2007 18:03 GMT On Aug 10, 12:46 pm, Manivannan Palanichamy <manivannan.palanich...@gmail.com> wrote:
> On Aug 10, 8:21 pm, "antonyliu2...@yahoo.com" > [quoted text clipped - 62 lines] > -- > Manivannan.Palanichamy (@) Oracle.comhttp://mani.gw.googlepages.com/index.html Interesting, so you are with me, and disagree with my colleague. Any comments from other OO gurus?
Alexey - 10 Aug 2007 18:36 GMT On Aug 10, 1:03 pm, "antonyliu2...@yahoo.com" <antonyliu2...@yahoo.com> wrote:
> On Aug 10, 12:46 pm, Manivannan Palanichamy > [quoted text clipped - 68 lines] > Interesting, so you are with me, and disagree with my colleague. Any > comments from other OO gurus? I tend to agree with your and GP's design. Generally speaking, it IS a good idea to assign "verbs" as methods to the actors. Other methods that Project may have would come no so much from actions, but perhaps requirements that detail what kind of information might be needed from within the Project entity. For example:
class Project { // ... getters and setters for simple data fields
Date getCompletionETA() Money estimateCost()
// some task management Set<Task> getTasks() Set<Task> getTasksAssignedTo(Employee emp) }
antonyliu2002@yahoo.com - 10 Aug 2007 19:24 GMT > On Aug 10, 1:03 pm, "antonyliu2...@yahoo.com" > [quoted text clipped - 90 lines] > > } Cool, sounds like that I have been correct, but my colleague was wrong. Feeling so proud. So, the principle is really simple: assign "verbs" as methods to the actors.
Mike Schilling - 10 Aug 2007 21:03 GMT > Your first design is correct. the design confusion is because of > unclear requirements. you should start from UseCase diagram, and then > will come to know what each Actor got to do. > > Anyway. In this case, the Project will be a a resource class. Like a > value object. So, obviously it will have only getters & setters. Quibble:
Suppose one of the things a project manager can do is combine two project, merging all of the resources associated with project A into project B. Agreed that there should be
ProjectManager.combineProjects(Project mergeInto, Project mergeFrom)
I don't think that this should be implemented by a list of get() and set() calls. The knowledge of what resources exist and how to merge them (as well as what state the cannibalized project goes into) belongs in the Project class. That is, if I add a new sort of resource to Project, it should be clear in the Project class what corresponding changes need to be made.
Thus this should be implemented as
combineProjects(Project absorbInto, Project cannibalizeFrom) { absorbInto.absorb(cannibalizeFrom); }
with the details of this processing in Project.absorb(). (Obviously, if the two projects were combined into a brand-new project, the work would be done in a Project constructor.)
Greg R. Broderick - 11 Aug 2007 18:17 GMT > Well, what can a ProjectManager do? I think s/he can > createNewProject, deleteProject, assignFundToProject, requestFund, > deleteFund, editProject, viewProjectList, etc. IMO, you've neglected one very important, frequently-invoked method for the ProjectManager class. I've provided a reference implementation below.
public class ProjectManager { ...
public void pesterWorkers() { System.out.println("What do you mean it isn't done yet?"); } }
Cheers GRB
 Signature --------------------------------------------------------------------- Greg R. Broderick usenet200707@blackholio.dyndns.org
A. Top posters. Q. What is the most annoying thing on Usenet? ---------------------------------------------------------------------
antonyliu2002@yahoo.com - 14 Aug 2007 17:01 GMT On Aug 11, 1:17 pm, "Greg R. Broderick" <usenet200...@blackholio.dyndns.org> wrote:
> "antonyliu2...@yahoo.com" <antonyliu2...@yahoo.com> wrote innews:1186759275.447652.206350@d30g2000prg.googlegroups.com: > [quoted text clipped - 26 lines] > Q. What is the most annoying thing on Usenet? > --------------------------------------------------------------------- Ha, that's a good joke. My Project Manager has been nice so far.
TobiMc3@gmail.com - 14 Aug 2007 19:21 GMT On Aug 11, 1:17 pm, "Greg R. Broderick" <usenet200...@blackholio.dyndns.org> wrote:
> "antonyliu2...@yahoo.com" <antonyliu2...@yahoo.com> wrote innews:1186759275.447652.206350@d30g2000prg.googlegroups.com: > [quoted text clipped - 26 lines] > Q. What is the most annoying thing on Usenet? > --------------------------------------------------------------------- LOL-Great minds!!
Tobi
TobiMc3@gmail.com - 14 Aug 2007 19:17 GMT On Aug 10, 11:21 am, "antonyliu2...@yahoo.com" <antonyliu2...@yahoo.com> wrote:
> OO Design continued. > [quoted text clipped - 16 lines] > class, because I think those are the things that a ProjectManager can > do. An aside:
I think you forgot yellAtDeveloper() :-)
Tobi
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|