Design Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nate

    #1

    Design Question

    Ladies and Gentlemen,

    I have 2 design questions for ya'll. And this pertains to developing an
    ASP.NET application.

    Question #1
    Which is the correct way (and why) for designing class methods?

    1. Use reference (input/output) parameters to return multiple pieces of
    information to the caller
    (please ignore naming conventions, for example only)
    public void MyFunc(int Param1, string Param2, ref int OutParam1, ref string
    OutParam2)
    {
    // do stuff
    OutParam1 = something;
    OutParam2 = somethingelse;
    }

    2. Pass back a object
    public MyClass MyFunc(int Param1, string Param2)
    {
    return new MyClass(somethi ng, somethingelse);
    }


    Question #2
    Which is the correct way (and why) for handling error conditions?

    1. Pass back an integer value indicating success or failure (like in the
    Win32api)

    2. Raise an exception
    throw new ApplicationExce ption("my error condition");
  • Peter Rilling

    #2
    Re: Design Question

    Your first question there really is no right or wrong. Different people
    will do it differently. I tend to prefer passing an object back with the
    information. I usually consider the parameters as only control mechanisms
    which change the methods behavior.

    With your second question, the accepted way of raising errors is to throw an
    exception. That does not mean that you will never return something else.
    For instance, if the caller is expecting an object, then the method might
    return a null if something bad happened.

    "Nate" <Nate@discussio ns.microsoft.co m> wrote in message
    news:51F8C2BF-AA42-40E9-841F-58E0A5987A48@mi crosoft.com...[color=blue]
    > Ladies and Gentlemen,
    >
    > I have 2 design questions for ya'll. And this pertains to developing an
    > ASP.NET application.
    >
    > Question #1
    > Which is the correct way (and why) for designing class methods?
    >
    > 1. Use reference (input/output) parameters to return multiple pieces of
    > information to the caller
    > (please ignore naming conventions, for example only)
    > public void MyFunc(int Param1, string Param2, ref int OutParam1, ref
    > string
    > OutParam2)
    > {
    > // do stuff
    > OutParam1 = something;
    > OutParam2 = somethingelse;
    > }
    >
    > 2. Pass back a object
    > public MyClass MyFunc(int Param1, string Param2)
    > {
    > return new MyClass(somethi ng, somethingelse);
    > }
    >
    >
    > Question #2
    > Which is the correct way (and why) for handling error conditions?
    >
    > 1. Pass back an integer value indicating success or failure (like in the
    > Win32api)
    >
    > 2. Raise an exception
    > throw new ApplicationExce ption("my error condition");[/color]


    Comment

    Working...