473,412 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

function call & architecture recommendations

TS
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(RegValidationArgs 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( IsAlreadyRegistered(this.ClassId, this.PartId) == true )
{
errorMessage = AlreadyRegisteredMsg;
return false;
}
}

Funding faFunding= Funding.GetFunding(args.AgentId, args.SourceId ,
args.Date);
// If one isn't found, then the Funding can't be used
if( faFunding == null )
{
errorMessage = CannotUseFundingSourceMsg;
return false;
}
}

}
Nov 17 '05 #1
5 1271
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 ValidationException
//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" <ma**********@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
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(RegValidationArgs 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( IsAlreadyRegistered(this.ClassId, this.PartId) == true )
{
errorMessage = AlreadyRegisteredMsg;
return false;
}
}

Funding faFunding= Funding.GetFunding(args.AgentId, args.SourceId ,
args.Date);
// If one isn't found, then the Funding can't be used
if( faFunding == null )
{
errorMessage = CannotUseFundingSourceMsg;
return false;
}
}

}

Nov 17 '05 #2
TS
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 RegValidationArgs
class and then have to add another parameter by reference. I don't know if
i should include the extra parameter inside the RegValidationArgs class as
well, or to do a different approach alltogether.

thanks for your input
"Jonathan Allen" <x@x.x> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
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 ValidationException
//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" <ma**********@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
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(RegValidationArgs 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( IsAlreadyRegistered(this.ClassId, this.PartId) == true )
{
errorMessage = AlreadyRegisteredMsg;
return false;
}
}

Funding faFunding= Funding.GetFunding(args.AgentId, args.SourceId ,
args.Date);
// If one isn't found, then the Funding can't be used
if( faFunding == null )
{
errorMessage = CannotUseFundingSourceMsg;
return false;
}
}

}


Nov 17 '05 #3
I would suggest merging the RegValidationArgs 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" <ma**********@nospam.nospam> wrote in message
news:uX**************@TK2MSFTNGP14.phx.gbl...
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
RegValidationArgs
class and then have to add another parameter by reference. I don't know
if
i should include the extra parameter inside the RegValidationArgs class as
well, or to do a different approach alltogether.

thanks for your input
"Jonathan Allen" <x@x.x> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
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 ValidationException
//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" <ma**********@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
> 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(RegValidationArgs 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( IsAlreadyRegistered(this.ClassId, this.PartId) == true )
> {
> errorMessage = AlreadyRegisteredMsg;
> return false;
> }
> }
>
> Funding faFunding= Funding.GetFunding(args.AgentId, args.SourceId ,
> args.Date);
> // If one isn't found, then the Funding can't be used
> if( faFunding == null )
> {
> errorMessage = CannotUseFundingSourceMsg;
> return false;
> }
> }
>
> }
>
>



Nov 17 '05 #4
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."

Nov 17 '05 #5
TS
Thank you all!
"TS" <ma**********@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
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(RegValidationArgs 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( IsAlreadyRegistered(this.ClassId, this.PartId) == true )
{
errorMessage = AlreadyRegisteredMsg;
return false;
}
}

Funding faFunding= Funding.GetFunding(args.AgentId, args.SourceId ,
args.Date);
// If one isn't found, then the Funding can't be used
if( faFunding == null )
{
errorMessage = CannotUseFundingSourceMsg;
return false;
}
}

}

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
10
by: Nitin | last post by:
Ppl , Want to have ur opinions on having function calls like the one stated below: function funcA ( struct A *st_A , struct B *st_B ) { st_A->a = st_B->a
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
15
by: marydeepthy | last post by:
Hi, I would like to know what happens internally when a c programme is executed. LIke, when we call a function, all the previous values will be pushed on to stack and the local variables of...
2
by: freegnu | last post by:
how to declare a friend function that can access two class it will look like the following class A { private: int i; public: A(){} ~A(){} friend void call(A &a, B &b);
7
by: Samuel | last post by:
Hi, I am looking for some recommendations for client/server technologies and for the communication involved. I am currently planning to port a Perl application that has grown out of...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
1
by: Cirene | last post by:
Do you have any good book recommendations for learning Entity Framework, DAAB, and/or Tiered Architecture (business objects, etc)? I am a VB.net developer, but C# would be ok I guess.... Thanks
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.