473,835 Members | 1,841 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 1600
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.c om...
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.c om...
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
6083
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
2628
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
3917
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 might be causing this and how I can fix it? Thanks.
4
3428
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
1408
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
1027
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 some sort of Best Practice. Anybody care to explain? -- PeteCresswell
1
9944
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
9653
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10563
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10237
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7770
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.