473,473 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

run base and inherited method

Public MustInherit Class A
Public Sub method1()
...
End sub
End Class

Partial Class B
Inherits A

Public Sub method1()
...
End sub
End Class

I create an instance of B, but when I call methodA, I would like that
1. would be executed method1 - base class A
2. then would be executed method1 - derived class B

is it possible? how?

tnx very much

Oct 25 '07 #1
5 1308
acadam wrote:
Public MustInherit Class A
Public Sub method1()
...
End sub
End Class

Partial Class B
Inherits A

Public Sub method1()
...
End sub
End Class
The compiler should be warning you about Shadowing method1(). IMHO,
Shadowing is a Bad Thing and should generally be avoided.

If you want to be able to change the behaviour of a method in a derived
class then mark the method as Overridable in the base class and
overrides in the derived class, as in:

Mustinherit Class A
Overridable Sub method1()

Class B
Inherits A
Overrides Sub method1()
I create an instance of B, but when I call methodA, I would like that
1. would be executed method1 - base class A
2. then would be executed method1 - derived class B

is it possible? how?
Yes; I don't know the "proper" term for it, but I call it "extending" a
method:

When you override a method, the Framework "unplugs" the original
implementation (from the base class) and "plugs in" your replacement
implementation (from your derived class) but the original is still
hanging around [somewhere] and you /can/ call it:

Overrides Sub method1()
' class the vase implementation
MyBase.method1()
' Now you can do something extra
End Sub

Or, perhaps, you might want to do something else /first/, and then go
back to the base implementation (this is a common model when handling
events in Control-derived classes).

Overrides Sub OnDoubleClick(e as EventArgs)
If Not Me.IgnoreDoubleClick Then
MyBase.OnDoubleClick( e )
End If
End Sub

HTH,
Phill W.
Oct 25 '07 #2
"acadam" <ac****@gmail.comschrieb
Public MustInherit Class A
Public Sub method1()
...
End sub
End Class

Partial Class B
Inherits A

Public Sub method1()
...
End sub
End Class
This can not be compiled, but see below....
I create an instance of B, but when I call methodA,
method1?
I would like
that
1. would be executed method1 - base class A
2. then would be executed method1 - derived class B

is it possible? how?
Public MustInherit Class A
Public Overridable Sub method1()
MsgBox("A")
End Sub
End Class

Partial Class B
Inherits A

Public Overrides Sub method1()
MyBase.method1()
MsgBox("B")
End Sub
End Class
Armin
Oct 25 '07 #3
Excuse me for jumping in.
What would you do if you had a UserControl that you wanted to have a Text
property that did something other than what the UserControl's Text property
does. Is that an exception or is there a better way than Shadowing?
thanks

">
The compiler should be warning you about Shadowing method1(). IMHO,
Shadowing is a Bad Thing and should generally be avoided.

Nov 8 '07 #4
Academia wrote:
What would you do if you had a UserControl that you wanted to have a Text
property that did something other than what the UserControl's Text property
does.
IIRC, the UserControl's Text Property is Overridable (VB'2003):

Public Class CustomControl
Inherits System.Windows.Forms.UserControl
.. . .
Public Overrides Property Text() _
As String

HTH,
Phill W.
Nov 9 '07 #5
I'll change now.

thanks

"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:fh**********@south.jnrs.ja.net...
Academia wrote:
>What would you do if you had a UserControl that you wanted to have a Text
property that did something other than what the UserControl's Text
property does.

IIRC, the UserControl's Text Property is Overridable (VB'2003):

Public Class CustomControl
Inherits System.Windows.Forms.UserControl
. . .
Public Overrides Property Text() _
As String

HTH,
Phill W.

Nov 9 '07 #6

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

Similar topics

8
by: TS | last post by:
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give me the code to do it? something like this?...
7
by: Santi | last post by:
I have two classes: Product and Fruit which inherits from Product. If I try to narrow the reference to the base type by a cast, I always get a reference to the inherited type. For example: ...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
7
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
12
by: Robert W. | last post by:
This question concerns something I'm trying to do with the CF but it's really a generic C# question. With the Compact Framework, one can't add a radio button with a long label because the labels...
8
by: Mike C# | last post by:
Suppose I have a base class "foo". Another class, "bar" derives from it. Base class "foo" has a method called "rob_the_liquor_store()", and the inherited class "bar" overrides this method with one...
5
by: Eliseu Rodrigues | last post by:
Hi I would like to have a static method on a base class that executes some action (for example retrieves the row count) on a table whose name is the same of the inherited class name. For...
19
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
12
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have a class which "BiologySequence" which looks about like this. public class BiologySequence { private string _Sequence; public string Sequence {
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
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
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,...
1
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
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.