473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you call a child objects method from the parent

Is it possible to call a method from a parent object, but have the
childs overriden method called instead of the base method?
I want several children objects to all call a certain method when they
are initialized, but they all have different implementations of that
method.
thanks

Nov 21 '05 #1
2 2319
In article <11************ **********@g14g 2000cwa.googleg roups.com>, jw*****@gmail.c om wrote:
Is it possible to call a method from a parent object, but have the
childs overriden method called instead of the base method?
I want several children objects to all call a certain method when they
are initialized, but they all have different implementations of that
method.
thanks


Two things... If your talking about constructors - then, it doesn't
matter because constructors are not inherited. So, each child class
will have it's own unique Sub New.

If your talking about a method that is called from a parent reference,
then you can do something like this:

Option Strict On
Option Explicit On

Module Module1

Sub Main()
Dim p As Parent

p = New Child1
p.Method()

p = New Child2
p.Method()

p = New Child3
p.Method()
End Sub

Private MustInherit Class Parent
Public MustOverride Sub Method()
End Class

Private Class Child1
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child1")
End Sub
End Class

Private Class Child2
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class

Private Class Child3
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class

End Module

If none of this actually answers your question... Hopefully someone
else will understand what your asking better :) Or, you can post some
air-code that sort of shows off what you're trying to do.

--
Tom Shelton [MVP]
Nov 21 '05 #2
In article <uF************ *@TK2MSFTNGP12. phx.gbl>, Tom Shelton wrote:
In article <11************ **********@g14g 2000cwa.googleg roups.com>, jw*****@gmail.c om wrote:
Is it possible to call a method from a parent object, but have the
childs overriden method called instead of the base method?
I want several children objects to all call a certain method when they
are initialized, but they all have different implementations of that
method.
thanks


Two things... If your talking about constructors - then, it doesn't
matter because constructors are not inherited. So, each child class
will have it's own unique Sub New.

If your talking about a method that is called from a parent reference,
then you can do something like this:

Option Strict On
Option Explicit On

Module Module1

Sub Main()
Dim p As Parent

p = New Child1
p.Method()

p = New Child2
p.Method()

p = New Child3
p.Method()
End Sub

Private MustInherit Class Parent
Public MustOverride Sub Method()
End Class

Private Class Child1
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child1")
End Sub
End Class

Private Class Child2
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class

Private Class Child3
Inherits Parent

Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class

End Module

If none of this actually answers your question... Hopefully someone
else will understand what your asking better :) Or, you can post some
air-code that sort of shows off what you're trying to do.


--
Tom Shelton [MVP]
Nov 21 '05 #3

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

Similar topics

2
3876
by: lkrubner | last post by:
My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed(); $this->arrayOfAllTheObjectsSoFarLoaded = & $object; if (method_exists($object, "setCallingCode")) $object->setCallingCode($nameOfFunctionOrClassCalling); return $object; } else {
9
5125
by: Martin Herbert Dietze | last post by:
Hello, I would like to implement a callback mechanism in which a child class registers some methods with particular signatures which would then be called in a parent class method. In half-code this should in the end look like this: In the child class:
26
45523
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function defined in "A.html", but every attempt results in an "is not a function" error. I have tried to invoke the function using parent.document.funcname(), top.document.funcname(), and various other identifying methods, but all result in the above...
5
1855
by: Steven C | last post by:
Hello: I've seen several recent threads on this, but I'm still not clear how to reference a *method* on one form from another. I want to add a customer in the child form, and then update the customers grid in the parent form. frmCustomers is the parent, and frmAddCustomer is the child. In frmCustomers, when the user clicks the ADD commandbutton, I call this code:
4
6526
by: ad | last post by:
base only can call the parent 's method The result of the example below is I am Parent I am Child How can we call the grandparent's method in a inhreited class, I want the result is I am GrandParent
33
1882
by: Partha Protim Roy | last post by:
Hello, I have a Customer form say A to enter/update customer details. In the Form A I have a button which opens another form say B. In the Form B, I am providing user with a option to search Customer from the database depending on various search criteria. On matching the criteria, list of Customer is displayed in the datagrid.
1
5689
by: Eric | last post by:
I want to call a method on the MDI parent from the child. Basically the method will set some text (message) on a status strip and show the appropriate icon (for the type of message). I'd also like to put a progress bar on the MDI parent and activate/manipulate it by the child What's the best way to do this? TIA
2
1845
by: Jack | last post by:
Hello, I have a 3-level class hirarchy: 1=Grandparent 2=Parent 3=Child The Grandparent has a method called OnPaint which I want to override from the Child class. I can do this, but how can I call the
29
3909
Frinavale
by: Frinavale | last post by:
I have 2 FireFox (version 2) browser windows opened. One is the child of the other. When the user is finished with the child window, a method in the parent window is called to refresh a section of the page. This is the JavaScript code that I'm using to refresh the content in the parent page: <script type="text/javascript"> function UpdateList() {
0
9423
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
10043
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
9990
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
9861
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...
1
7406
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...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
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...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.