471,318 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Shall I use an Event/Delegate way or just the compare value way?

Hi colleagues,

In fact I don't have a problem but just don't know which way is good
and better.

I need some advice which programming way I shall use. Since a couple
of days I'm investing my knowledge in Events and Delegates to get more
used to it.

Here I've situation which way should you use and why?

I've a page an ASPX page named. Creditlimit.aspx and a business logic
class Bank.cs.

In Creditlimit.aspx I'm setting the creditlimits for a customer.
e.g. customerID A1001 has creditlimit 1250$, CustomerID B5404 has
creditlimit 1550$.
So I can set the creditlimit. I also have in another help table the
global creditlimit set value 2500$.
So no one customer should exceed this creditlimit. I mean when the
user enters 3500$ the application won't allow it to set.

I've solved this problem in 2 ways:

Way 1 - Traditional way:
-------------------------------------------------
In Creditlimit.aspx.cs (code behind)
I retrieve the global creditlimit calling a function in business logic
(class bank: method: GetglbCreditLimit) to get global creditlimit,
which returns me 3500$ and put that in an decimal field in aspx.cs
(code behind page).
then I compare the value (textbox control) with this value. If it
exceed the global credit limit it just send a status/error message to
the screen that it's not allowed. So I just compare the 2 field
values....

Ok this was the easy way. it's clear and easy.
Way 2 - Event Delegate way:
--------------------------------------------------
Here I'm using a delegate/event handler way.
I've created a Delegate and a event.

public delegate void OverCreditLimit(object o,
CreditLimitEventArgs e);
public class CreditLimit
{
public event OverCreditLimit NSF; //non-sufficient funds
.....
then I'm calling the CheckOverlimit function in business logic in Bank
class. if the entered credilimit/requested credit limit is than
GlobalCreditlimit, It trigger the event and invokes the delegate.

in aspx page I've set the eventhandler to property eventhandler
property see below...
//check credit limit - it should not exceed the global
credit limit set up in UDC:Finance/Creditlimit
Bank objBank = new Bank();
objBank .NSF += CheckCreditLimitHandler; // set to a
function that it diplays the error on the page

so when it exceeds CheckCreditLimit in Aspx.cs page displays the
error.
SO My question is in fact.... Both methods gives me the SAME result...
Why should I choose for the Event/Delegate method or why not?????????

I'm a little bit confused when to use event/delegates and when not? In
this circumstances would you use it or not?

thanks for sharing your thoughts,

mesut
Jul 30 '08 #1
1 1312
On Wed, 30 Jul 2008 01:10:06 -0700, mesut <me*********@noveonbe.comwrote:
[...]
SO My question is in fact.... Both methods gives me the SAME result...
Why should I choose for the Event/Delegate method or why not?????????

I'm a little bit confused when to use event/delegates and when not? In
this circumstances would you use it or not?
You posted in the wrong newsgroup to get a really good answer. One
specific to ASP.NET would provide much better insight as to implementation
details in this situation.

That said, for me the big issue is separation of different kinds of logic
in your program and the ability to reuse your code. In your first
approach, your error handling is tied strongly to your user presentation.
In the second, the code that handles the error handling and data analysis
doesn't need to know anything at all about your user presentation.

This is often the distinction between using hard-coded callbacks and
delegates/events. So perhaps this is sufficient for your needs. If not,
I recommend asking people who are more knowledgeable about ASP.NET
specifically.

Pete
Jul 31 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andy Read | last post: by
3 posts views Thread by Guadala Harry | last post: by
6 posts views Thread by David Veeneman | last post: by
7 posts views Thread by tony | last post: by
22 posts views Thread by dvestal | last post: by
reply views Thread by pjr | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by rosydwin | last post: by

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.