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

opinions with OnXXX overrides.

I would like people's opinions. Many classes have an Onxxx that actually
invokes the registered event handlers. A derived class can override these
methods rather then registering an event. The consequence of this is that
the overridden class must call the parents' method so that events are
dispatched.

My question is, is it better to call the parents' method at the beginning of
the override, or at the end, as the last statement?
Nov 16 '05 #1
2 1317
I guess it all depends on what the method is suppose to do and what you are
trying to accomplish. Look at OnPaint, for example. Would you like the
end-developer, or yourself, to be able to draw on the surface of the control
through the Paint event? If you call the base classes OnPaint first then any
painting that you do may paint over anything that a registered Paint event
handler has done. If you call OnPaint last then you are allowing a
registered Paint event handler to draw over any painting that you did. So I
guess it all depends on what you are trying to accomplish and what the base
class is actually doing.

--
Tim Wilson
..Net Compact Framework MVP

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:ur*************@TK2MSFTNGP12.phx.gbl...
I would like people's opinions. Many classes have an Onxxx that actually
invokes the registered event handlers. A derived class can override these
methods rather then registering an event. The consequence of this is that
the overridden class must call the parents' method so that events are
dispatched.

My question is, is it better to call the parents' method at the beginning of the override, or at the end, as the last statement?

Nov 16 '05 #2

Depends on the event what the base class is doing besides raising the
event, if anything.

If the event is cancellable then and you want your processing to only
be done if nothing cancelled the event, then call base first. If you
want the first crack at cancelling the event, then call base last.

In other cases there could be additional processing in the base that
you want to do either before or after your code and it depends
entirely on what specific processing is done. There is no general
rule.

HTH,

Sam
On Tue, 1 Mar 2005 13:40:34 -0800, "Peter Rilling"
<pe***@nospam.rilling.net> wrote:
I would like people's opinions. Many classes have an Onxxx that actually
invokes the registered event handlers. A derived class can override these
methods rather then registering an event. The consequence of this is that
the overridden class must call the parents' method so that events are
dispatched.

My question is, is it better to call the parents' method at the beginning of
the override, or at the end, as the last statement?


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 16 '05 #3

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

Similar topics

3
by: ECVerify.com | last post by:
I posted this earlier but never got a response...so I am trying again **************************** Hey everyone, I have a simple (I hope question) To get the events in C# I can go to the...
4
by: Christopher W. Douglas | last post by:
I am developing a VB.NET app using Visual Studio.NET 2003. VB.NET allows me to create a class with two or more methods that have the same name, as long as they have different (non-optional)...
3
by: John Doe | last post by:
I've been doing some reading/research on parsing simple configuration files through C, and have heard various opinions on the matter. I'd like to solicit some opinions and design criteria (as well...
3
by: Ben | last post by:
Hi There I am doing some unit testing at the moment, and the majority of the leg work involves taking two objects (expected vs actual) and verifying that their properties are equal. The objects...
9
by: Surrealist | last post by:
I need something likes as when I create an event procedure. I can use top-left and top-right dropdown list of code editor to select object and its exposed events respectively. Then, the IDE,...
10
by: Atif | last post by:
Hi I am here to solve a small confusion i have in "Overloads Overrides". "Overloading" says that the method's name should be same while no. of parameters and/or their datatypes should be changed...
2
by: Kalvin | last post by:
I found some code in Google, don't remember where, for an AutoComplete combobox. Everything is great with it except for one thing. If I use the mouse to drop the list down, then start typing to...
2
by: tony | last post by:
Hello !! I have a question about event. This small program below is taken from the internet and I wonder if there are any advantage to use this Onxxx in this case it's OnEventSeven instead of...
12
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...

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.