473,516 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1565
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
6060
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 the workspace and then: Build>Batch Build
16
2606
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 string is directly generated in the code. But it doesn't works if I wait for this inside a 'while' loop. This is the simple code: global stringZVEI
5
3904
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) but only sometimes. Other times it appears behind the parent form and all that is visible is the last few characters of that row. Anyone know what...
4
3382
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 RaiseCallbackEvent(string eventArgs) { // update the data object with the values currently on screen FormView1.UpdateItem(true); }
3
1392
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: function MyControl_Enter(...) handles MyControl.Enter or I can overwrite the relevant virtual method:
3
1011
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 timer would affect? just curious, rodchar
2
315
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 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...
1
9930
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). (http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx) Question: Is it better and easier now in ASPNET 2.0 , meaning VS 2005?
4
237
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: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.