function call & architecture recommendations

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

    #1

    function call & architecture recommendations

    From my presentation layer, I call a validation method in my business layer
    that i pass a custom class to that holds all parameters. I am currently also
    passing an error message by reference so that the calling code can have this
    string set to an error message inside this method.

    I'm wondering 2 things:
    1. Should i put the errorMessage param as a property on args and pass the
    whole thing as reference?

    2. Is there a more elegant approach to handling validation that occurs on
    this separate business layer?

    thanks a lot!
    public bool CanReg(RegValid ationArgs args, ref string errorMessage)
    {
    // Call method to validate isn't already registered if this is a new
    record
    if( this.IsNew )
    { // make sure isn't already registered
    if( IsAlreadyRegist ered(this.Class Id, this.PartId) == true )
    {
    errorMessage = AlreadyRegister edMsg;
    return false;
    }
    }

    Funding faFunding= Funding.GetFund ing(args.AgentI d, args.SourceId ,
    args.Date);
    // If one isn't found, then the Funding can't be used
    if( faFunding == null )
    {
    errorMessage = CannotUseFundin gSourceMsg;
    return false;
    }
    }

    }


  • Jonathan Allen

    #2
    Re: function call & architecture recommendations

    Create one class called Registration. Use it for storing the values,
    validating their contents, and committing the transaction. That one class,
    and its underlying database connections, is you business layer.

    X = new Registration()
    X.FundingSource = ???
    X.LastName = ??
    X.FirstName = ??
    try
    X.Commit();
    catch ex ValidationExcep tion
    //return ex.Message to the user
    end try

    ***************

    The point here is that your presentation and business layers don't have to
    be physically separated. As long as you can look at the code and say, this
    class holds my business rules and that form interacts with the user, you've
    done your job.

    --
    Jonathan Allen


    "TS" <manofsteele1@n ospam.nospam> wrote in message
    news:OjBw7F4aFH A.2520@TK2MSFTN GP09.phx.gbl...[color=blue]
    > From my presentation layer, I call a validation method in my business
    > layer
    > that i pass a custom class to that holds all parameters. I am currently
    > also
    > passing an error message by reference so that the calling code can have
    > this
    > string set to an error message inside this method.
    >
    > I'm wondering 2 things:
    > 1. Should i put the errorMessage param as a property on args and pass the
    > whole thing as reference?
    >
    > 2. Is there a more elegant approach to handling validation that occurs on
    > this separate business layer?
    >
    > thanks a lot!
    > public bool CanReg(RegValid ationArgs args, ref string errorMessage)
    > {
    > // Call method to validate isn't already registered if this is a new
    > record
    > if( this.IsNew )
    > { // make sure isn't already registered
    > if( IsAlreadyRegist ered(this.Class Id, this.PartId) == true )
    > {
    > errorMessage = AlreadyRegister edMsg;
    > return false;
    > }
    > }
    >
    > Funding faFunding= Funding.GetFund ing(args.AgentI d, args.SourceId ,
    > args.Date);
    > // If one isn't found, then the Funding can't be used
    > if( faFunding == null )
    > {
    > errorMessage = CannotUseFundin gSourceMsg;
    > return false;
    > }
    > }
    >
    > }
    >
    >[/color]


    Comment

    • TS

      #3
      Re: function call &amp; architecture recommendations

      this is how i have it. The method on my business layer i was referring to is
      in my registration class. My main question is how to appropriately pass back
      the error messages from the registration class to the UI for display. How i
      have it is that i pass all needed params to the method in a class that hold
      all of them, then i also send a parameter by reference so that the
      registration class can set its value so the calling code in the UI now has
      the error message.

      I just don't like having all the parameters housed in the RegValidationAr gs
      class and then have to add another parameter by reference. I don't know if
      i should include the extra parameter inside the RegValidationAr gs class as
      well, or to do a different approach alltogether.

      thanks for your input


      "Jonathan Allen" <x@x.x> wrote in message
      news:Oejjpy5aFH A.3808@TK2MSFTN GP14.phx.gbl...[color=blue]
      > Create one class called Registration. Use it for storing the values,
      > validating their contents, and committing the transaction. That one class,
      > and its underlying database connections, is you business layer.
      >
      > X = new Registration()
      > X.FundingSource = ???
      > X.LastName = ??
      > X.FirstName = ??
      > try
      > X.Commit();
      > catch ex ValidationExcep tion
      > //return ex.Message to the user
      > end try
      >
      > ***************
      >
      > The point here is that your presentation and business layers don't have to
      > be physically separated. As long as you can look at the code and say, this
      > class holds my business rules and that form interacts with the user,[/color]
      you've[color=blue]
      > done your job.
      >
      > --
      > Jonathan Allen
      >
      >
      > "TS" <manofsteele1@n ospam.nospam> wrote in message
      > news:OjBw7F4aFH A.2520@TK2MSFTN GP09.phx.gbl...[color=green]
      > > From my presentation layer, I call a validation method in my business
      > > layer
      > > that i pass a custom class to that holds all parameters. I am currently
      > > also
      > > passing an error message by reference so that the calling code can have
      > > this
      > > string set to an error message inside this method.
      > >
      > > I'm wondering 2 things:
      > > 1. Should i put the errorMessage param as a property on args and pass[/color][/color]
      the[color=blue][color=green]
      > > whole thing as reference?
      > >
      > > 2. Is there a more elegant approach to handling validation that occurs[/color][/color]
      on[color=blue][color=green]
      > > this separate business layer?
      > >
      > > thanks a lot!
      > > public bool CanReg(RegValid ationArgs args, ref string errorMessage)
      > > {
      > > // Call method to validate isn't already registered if this is a new
      > > record
      > > if( this.IsNew )
      > > { // make sure isn't already registered
      > > if( IsAlreadyRegist ered(this.Class Id, this.PartId) == true )
      > > {
      > > errorMessage = AlreadyRegister edMsg;
      > > return false;
      > > }
      > > }
      > >
      > > Funding faFunding= Funding.GetFund ing(args.AgentI d, args.SourceId ,
      > > args.Date);
      > > // If one isn't found, then the Funding can't be used
      > > if( faFunding == null )
      > > {
      > > errorMessage = CannotUseFundin gSourceMsg;
      > > return false;
      > > }
      > > }
      > >
      > > }
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Jonathan Allen

        #4
        Re: function call &amp; architecture recommendations

        I would suggest merging the RegValidationAr gs into the class that has CanReg
        method. As fort passing the human-readable error message by ref, that sounds
        good to me.

        --
        Jonathan Allen


        "TS" <manofsteele1@n ospam.nospam> wrote in message
        news:uX38Xb6aFH A.2124@TK2MSFTN GP14.phx.gbl...[color=blue]
        > this is how i have it. The method on my business layer i was referring to
        > is
        > in my registration class. My main question is how to appropriately pass
        > back
        > the error messages from the registration class to the UI for display. How
        > i
        > have it is that i pass all needed params to the method in a class that
        > hold
        > all of them, then i also send a parameter by reference so that the
        > registration class can set its value so the calling code in the UI now has
        > the error message.
        >
        > I just don't like having all the parameters housed in the
        > RegValidationAr gs
        > class and then have to add another parameter by reference. I don't know
        > if
        > i should include the extra parameter inside the RegValidationAr gs class as
        > well, or to do a different approach alltogether.
        >
        > thanks for your input
        >
        >
        > "Jonathan Allen" <x@x.x> wrote in message
        > news:Oejjpy5aFH A.3808@TK2MSFTN GP14.phx.gbl...[color=green]
        >> Create one class called Registration. Use it for storing the values,
        >> validating their contents, and committing the transaction. That one
        >> class,
        >> and its underlying database connections, is you business layer.
        >>
        >> X = new Registration()
        >> X.FundingSource = ???
        >> X.LastName = ??
        >> X.FirstName = ??
        >> try
        >> X.Commit();
        >> catch ex ValidationExcep tion
        >> //return ex.Message to the user
        >> end try
        >>
        >> ***************
        >>
        >> The point here is that your presentation and business layers don't have
        >> to
        >> be physically separated. As long as you can look at the code and say,
        >> this
        >> class holds my business rules and that form interacts with the user,[/color]
        > you've[color=green]
        >> done your job.
        >>
        >> --
        >> Jonathan Allen
        >>
        >>
        >> "TS" <manofsteele1@n ospam.nospam> wrote in message
        >> news:OjBw7F4aFH A.2520@TK2MSFTN GP09.phx.gbl...[color=darkred]
        >> > From my presentation layer, I call a validation method in my business
        >> > layer
        >> > that i pass a custom class to that holds all parameters. I am currently
        >> > also
        >> > passing an error message by reference so that the calling code can have
        >> > this
        >> > string set to an error message inside this method.
        >> >
        >> > I'm wondering 2 things:
        >> > 1. Should i put the errorMessage param as a property on args and pass[/color][/color]
        > the[color=green][color=darkred]
        >> > whole thing as reference?
        >> >
        >> > 2. Is there a more elegant approach to handling validation that occurs[/color][/color]
        > on[color=green][color=darkred]
        >> > this separate business layer?
        >> >
        >> > thanks a lot!
        >> > public bool CanReg(RegValid ationArgs args, ref string errorMessage)
        >> > {
        >> > // Call method to validate isn't already registered if this is a new
        >> > record
        >> > if( this.IsNew )
        >> > { // make sure isn't already registered
        >> > if( IsAlreadyRegist ered(this.Class Id, this.PartId) == true )
        >> > {
        >> > errorMessage = AlreadyRegister edMsg;
        >> > return false;
        >> > }
        >> > }
        >> >
        >> > Funding faFunding= Funding.GetFund ing(args.AgentI d, args.SourceId ,
        >> > args.Date);
        >> > // If one isn't found, then the Funding can't be used
        >> > if( faFunding == null )
        >> > {
        >> > errorMessage = CannotUseFundin gSourceMsg;
        >> > return false;
        >> > }
        >> > }
        >> >
        >> > }
        >> >
        >> >[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Kevin Yu [MSFT]

          #5
          Re: function call &amp; architecture recommendations

          Thanks fro Jonathan's quick response!

          Hi TS,

          I think it's fine to pass a string back to the caller by reference.
          However, there are also some other ways. For example, you can thrown an
          exception if the validation fails and include the error message in the
          exception message. In the call code, you just catch this exception and
          display it. HTH.

          Kevin Yu
          =======
          "This posting is provided "AS IS" with no warranties, and confers no
          rights."

          Comment

          • TS

            #6
            Re: function call &amp; architecture recommendations

            Thank you all!


            "TS" <manofsteele1@n ospam.nospam> wrote in message
            news:OjBw7F4aFH A.2520@TK2MSFTN GP09.phx.gbl...[color=blue]
            > From my presentation layer, I call a validation method in my business[/color]
            layer[color=blue]
            > that i pass a custom class to that holds all parameters. I am currently[/color]
            also[color=blue]
            > passing an error message by reference so that the calling code can have[/color]
            this[color=blue]
            > string set to an error message inside this method.
            >
            > I'm wondering 2 things:
            > 1. Should i put the errorMessage param as a property on args and pass the
            > whole thing as reference?
            >
            > 2. Is there a more elegant approach to handling validation that occurs on
            > this separate business layer?
            >
            > thanks a lot!
            > public bool CanReg(RegValid ationArgs args, ref string errorMessage)
            > {
            > // Call method to validate isn't already registered if this is a new
            > record
            > if( this.IsNew )
            > { // make sure isn't already registered
            > if( IsAlreadyRegist ered(this.Class Id, this.PartId) == true )
            > {
            > errorMessage = AlreadyRegister edMsg;
            > return false;
            > }
            > }
            >
            > Funding faFunding= Funding.GetFund ing(args.AgentI d, args.SourceId ,
            > args.Date);
            > // If one isn't found, then the Funding can't be used
            > if( faFunding == null )
            > {
            > errorMessage = CannotUseFundin gSourceMsg;
            > return false;
            > }
            > }
            >
            > }
            >
            >[/color]


            Comment

            Working...