473,406 Members | 2,549 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,406 software developers and data experts.

Significance of calling the base

In some examples with inheriting, I see the overloaded function always
call its base. For instance, in this case where the ListView control is
being extended.

public class ListViewEx : System.Windows.Forms.ListView
{
protected override void OnColumnClick(ColumnClickEventArgs e)
{
...various code to extend the control

base.OnColumnClick (e);
}
}

What is the significance of the base.OnColumnClick(e)? Is it needed or
is it superfluous? In some examples I see it, in others I don't. Is
there a rule for this?

Thanks.
Nov 16 '05 #1
4 1241
it depends on whether you want the base class's OnColumnClick code to run or
not. Sometimes you'll want to completely replace what the base class does
(and you won't call the base class's method), and sometimes you want to
augment what it does (and you'd want to call the base method)

--
Floyd Burger

"Frank Rizzo" <no**@none.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
In some examples with inheriting, I see the overloaded function always
call its base. For instance, in this case where the ListView control is
being extended.

public class ListViewEx : System.Windows.Forms.ListView
{
protected override void OnColumnClick(ColumnClickEventArgs e)
{
...various code to extend the control

base.OnColumnClick (e);
}
}

What is the significance of the base.OnColumnClick(e)? Is it needed or
is it superfluous? In some examples I see it, in others I don't. Is
there a rule for this?

Thanks.

Nov 16 '05 #2
Frank Rizzo <no**@none.com> wrote:
In some examples with inheriting, I see the overloaded function always
call its base. For instance, in this case where the ListView control is
being extended.

public class ListViewEx : System.Windows.Forms.ListView
{
protected override void OnColumnClick(ColumnClickEventArgs e)
{
...various code to extend the control

base.OnColumnClick (e);
}
}

What is the significance of the base.OnColumnClick(e)? Is it needed or
is it superfluous? In some examples I see it, in others I don't. Is
there a rule for this?


Well, if you don't call the base implementation, then it obviously
won't do what it would normally do - such as fire the ColumnClick event
in this case. Sometimes you do want to call the base method, sometimes
you don't - but there's no general rule that I know of.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Jon Skeet [C# MVP] wrote:
Frank Rizzo <no**@none.com> wrote:
In some examples with inheriting, I see the overloaded function always
call its base. For instance, in this case where the ListView control is
being extended.

public class ListViewEx : System.Windows.Forms.ListView
{
protected override void OnColumnClick(ColumnClickEventArgs e)
{
...various code to extend the control

base.OnColumnClick (e);
}
}

What is the significance of the base.OnColumnClick(e)? Is it needed or
is it superfluous? In some examples I see it, in others I don't. Is
there a rule for this?

Well, if you don't call the base implementation, then it obviously
won't do what it would normally do - such as fire the ColumnClick event
in this case. Sometimes you do want to call the base method, sometimes
you don't - but there's no general rule that I know of.


Given that I don't have the source for the ListView control, how would I
know whether or not I should call the base for each specific case?
Nov 16 '05 #4
Frank Rizzo <no**@none.com> wrote:
Well, if you don't call the base implementation, then it obviously
won't do what it would normally do - such as fire the ColumnClick event
in this case. Sometimes you do want to call the base method, sometimes
you don't - but there's no general rule that I know of.


Given that I don't have the source for the ListView control, how would I
know whether or not I should call the base for each specific case?


Well, do you want it to do what it would normally do or not? For the
OnXXX, it's really "do you want the normal events to fire" to which the
answer is usually yes, I'd expect.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

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

Similar topics

3
by: Anonymous | last post by:
In PHP Whats the difference between $yourname = @$_POST; AND $yourname = $_POST; In particular, what is the significance of '@' as a prefix to the variable? Thanks in advance
4
by: Martin Maney | last post by:
I've been to the cookbook (both forms, since they're sometimes usefully different), but that gave rise to more questions than answers. Heck, let me pull some of them up while I'm at it. ...
6
by: Justin | last post by:
Hello, first time posting. If I have a base class and a derived class, is there only one way to call the base constructor? i.e. Is this the only way I can call the base constructor...
5
by: kernel.lover | last post by:
hello, I want to know if a fuction say malloc is declared as void *malloc() then whats the significance of void here. Does void * is used when function has the flexibility to return any type of...
5
by: Dave Veeneman | last post by:
I'm using inheritance more than I used to, and I find myself calling a lot of base class methods. I generally call a base method from a dreived class like this: this.MyMethod(); I'm finding...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
4
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, what is the use-case of parameter "start" in string's "endswith" method? Consider the following minimal example: a = "testing" suffix="ing" a.endswith(suffix, 2) Significance of...
26
by: joe | last post by:
My experiments show that the random number generator in Microsoft's VC++6 compiler is a statistical RNG with a significance level 1.0%. Statistical testing at SL >1.0% (for example 1.001%) passes...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.