Results 1 to 5 of 5

Thread: where should I put this method (class design question)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    589

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Banned
    Join Date
    Oct 2006
    Posts
    24

    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

  4. #4
    New Member
    Join Date
    Aug 2005
    Posts
    1

    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

  5. #5
    Addicted Member
    Join Date
    Nov 2006
    Posts
    132

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width