473,947 Members | 2,669 Online
Bytes | Software Development & Data Engineering Community
+ 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 1327
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.IgnoreDouble Click Then
MyBase.OnDouble Click( e )
End If
End Sub

HTH,
Phill W.
Oct 25 '07 #2
"acadam" <ac****@gmail.c omschrieb
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.UserContr ol
.. . .
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.j a.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.UserContr ol
. . .
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
3090
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? this.GetType().GetMember("panel1").SetValue(xx).Left = 44;
7
5768
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: Fruit lemon = new Fruit(); Product prod = (Product)lemon; // Now prod is a Fruit Type!! I want to get a Product reference from a Fruit object, is it possible? thank you.
5
3173
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 CommonPageBase - Contains myPage which inherits PageBase Each of these classes overrides OnInit and ties an event handler
4
2874
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. '**************************************************************************** ' Issues '****************************************************************************
7
2267
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 me. So, I'm here for an answer (more of a confirmation), hopefully. First let me say that I know people keep saying; it doesn't work because the member "is a private". I believe there's more to it than just simply that... Theory: You inherit,...
12
10149
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 don't wrap. So I've decided to create my own custom radio button. With my version there will be a basic radio button with no text and its size reduced to 12 x 12. Then beside this I will place a LinkLabel, which will wrap, to give the...
8
2037
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 of its own, maybe specifying the liquor store over on 44th Street and 5th Avenue or something. Anyway this is what we have so far: base class: "foo" |------------method: "rob_the_liquor_store()" |
5
3618
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 example: Assume that my base class has a static method named GetRowCount().
19
2257
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 modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer defined. The relationship between them is one to many. We created our own versions (inherited) of Map...
12
2184
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
10162
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11571
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
11155
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
11344
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
10690
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
6113
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
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.