473,387 Members | 1,435 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,387 software developers and data experts.

Noob Question: Why raise envents instead of executing event code?

I've been perusing a "real-life" application and notice that for instance, in a
button's Click() event, they don't write the processing code. Instead, they
raise an event like AddNewRecord and then put the coding that would have been in
the click event in the AddNewRecord event handler.

It seems TB throughout the app, so I'm guessing it's some sort of Best Practice.

Anybody care to explain?
--
PeteCresswell
Jul 21 '05 #1
2 1549
Hi Pete,

This can often be seen as a question of style or what the application calls
for. There are two main reasons I might do this. One would be to separate
out the business rules from the interface. The other would be that there
might be multiple objects that have some reason to care that the button has
been clicked. By raising the event, any other subscribed eventhandler would
be able to also take action. Although, I believe eventhandlers could
subscribe to the button's click event rather than it having to spawn a new
one.

HTH,

John

"(Pete Cresswell)" <x@y.z> wrote in message
news:gu********************************@4ax.com...
I've been perusing a "real-life" application and notice that for instance, in a button's Click() event, they don't write the processing code. Instead, they raise an event like AddNewRecord and then put the coding that would have been in the click event in the AddNewRecord event handler.

It seems TB throughout the app, so I'm guessing it's some sort of Best Practice.
Anybody care to explain?
--
PeteCresswell

Jul 21 '05 #2
I doubt that this is a best practice. I've certainly never heard of this as
any kind of best practice.

an event that fires an event, sounds like the author wanted to play with
events.
Code for the sake of code usually adds unneeded complexity. That increases
the cost of maintenance and increases the liklihood of errors.

There are some elegant ways to seperate business rules from UI. Event
indirection isn't one that comes to mind.

Regardless, if you have to keep this code working, and it is already
working, no point in changing it. Stick with the model in this app.

Just try not to learn from it.

My $0.02
--- Nick

"(Pete Cresswell)" <x@y.z> wrote in message
news:gu********************************@4ax.com...
I've been perusing a "real-life" application and notice that for instance, in a button's Click() event, they don't write the processing code. Instead, they raise an event like AddNewRecord and then put the coding that would have been in the click event in the AddNewRecord event handler.

It seems TB throughout the app, so I'm guessing it's some sort of Best Practice.
Anybody care to explain?
--
PeteCresswell

Jul 21 '05 #3

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

Similar topics

3
by: We need more power captain | last post by:
Hi, I know less than a noob, I've been asked to do some compiles in VC++ 6 without knowing too much at all. (I'm a COBOL program normally so this is all too much for me) I open VC++6, open...
16
by: dario | last post by:
Hi, Im new on phyton programming. On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive a string from serial port and after send this one enclosed in an e-mail. All OK if the...
5
by: rh | last post by:
I created a user control that is made up of a TreeView and a VScrollBar. I set the TreeView.FullRowSelect = True and it works as expected (full row is visible, appears on top of everything else)...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
3
by: James Ramaley | last post by:
I have created a VB.NET User Control which inherits from TextBox. I have a general question regarding how functionality should be overwritten: I can either write a method which handles an event:...
3
by: rodchar | last post by:
hey all, if i have a timer program that ticks every 1/100th of a second and it just checks a variable status would that be a huge hit on the performance of the system or whatever indicator the...
2
by: (Pete Cresswell) | last post by:
I've been perusing a "real-life" application and notice that for instance, in a button's Click() event, they don't write the processing code. Instead, they raise an event like AddNewRecord and...
1
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them)....
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.