where should I put this method (class design question)
Hi,
if i am working on bug tracking system for example where technical support agents log (or create) new bugs in the system.
In this situation, I guess we ll have an employee (or supportAgent class) and a bug class.
So where should I put the method: createNewBug
in the supportAgent class or in the Bug class or both
Pls let me know if my question doesn t make sense.
Thank you
Re: where should I put this method (class design question)
From what you've posted I would think that the SupportAgent class would have a CreateNewBug method that returned a Bug object.
Re: where should I put this method (class design question)
Definately in the Agent class, think of it logically as "Agent creates a Bug Tracker record". In reality what we do in the real-world mimics how objects interact with one another. I had to create something similiar to a bug tracking tool, well in reality it is the same thing now that I think about it. I had to create an issues system where an issue points back to some actions or rules associated with an issue.
So once the Issue object was instantiated and all of its properties were set (the non-nullable ones). I was able to allow end users to CreateNewAction and have it return an Action Item datatype.
In your case:
public class UserAgent
....
private Function CreateNewBug() as Bug
Dim b as New Bug
'set some properties of b
b.SetItsDate()
b.SetItsDescription()
return b
end function
end class
Re: where should I put this method (class design question)
for arguments sake i would disagree. the serviceagent object will eventually become bloated and unmanageable if you get into the habit of sticking functional operations in there only because they appear to logically fit. I would suggest some sort of bug factory or bug manager class to create/manage new bug objects
if new bug creation is only a small part of the serviceAgent’s job and there are times when a serviceAgent wont even execute that particular method then I, personally, would factor it out
cheers
Re: where should I put this method (class design question)
I can see no logic that would make sense for this to be a member of the SupportAgent class.
Given the two choices, this is clearly a method of the Bug class.
Of course, you also have to define what CreateNewBug does.
Is it merely the "save" function of a bug object that hasn't yet been persisted to the database? Or is it a creational method, that actually returns a newly instantiated bug object with all its default values populated or set to values passed in as parameteres.
In the first case, it is an instance member of Bug.
In the second, it would be a static member of Bug, or, as presented in the previous post, the factory idea could be used where a separate factory object would create the new Bug object, but at this stage of your thinking, it would suffice to use the Factory Method pattern and make CreateNewBug a static member of the Bug class.
Another alternative that is commonly followed is to have a BugList object that is a collection of bugs that are somehow related - such as by module, or date, or whatever - and the BugList object acts as the factory for creating new bugs.