473,836 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find out child type in base class call?

Hi,

Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load.
But without overloading Load in Sandal and sending the Sandal type to
the base class I can not instantiate a Sandal class from within Shoe.

Public Class Shoe
Public Shared Function Load() As Object
return ?????
End Function
End Class

Public Class Sandal
Inherits Shoe
End Class

Public Class MyShoeBox
Private mySandal as Sandal = Sandal.Load()
End Class

So, my question is: Is it possible to find out the type/class which was
actually called from within the base class?

Kind regards,
Roland

Jun 22 '06 #1
6 3625
I have a suggestion - how about defining your sandal class, and inherit
the shoe class?

T

ro*********@gma il.com wrote:
Hi,

Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load.
But without overloading Load in Sandal and sending the Sandal type to
the base class I can not instantiate a Sandal class from within Shoe.

Public Class Shoe
Public Shared Function Load() As Object
return ?????
End Function
End Class

Public Class Sandal
Inherits Shoe
End Class

Public Class MyShoeBox
Private mySandal as Sandal = Sandal.Load()
End Class

So, my question is: Is it possible to find out the type/class which was
actually called from within the base class?

Kind regards,
Roland

Jun 22 '06 #2
Roland,

You mean GetType?

http://msdn.microsoft.com/library/de...ttypetopic.asp

Cor

<ro*********@gm ail.com> schreef in bericht
news:11******** *************@m 73g2000cwd.goog legroups.com...
Hi,

Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load.
But without overloading Load in Sandal and sending the Sandal type to
the base class I can not instantiate a Sandal class from within Shoe.

Public Class Shoe
Public Shared Function Load() As Object
return ?????
End Function
End Class

Public Class Sandal
Inherits Shoe
End Class

Public Class MyShoeBox
Private mySandal as Sandal = Sandal.Load()
End Class

So, my question is: Is it possible to find out the type/class which was
actually called from within the base class?

Kind regards,
Roland

Jun 23 '06 #3
Hello, Roland,

Possibly something like:

Return Activator.Creat eInstance(Me.Ge tType)

Cheers,
Randy
ro*********@gma il.com wrote:
Hi,

Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load.
But without overloading Load in Sandal and sending the Sandal type to
the base class I can not instantiate a Sandal class from within Shoe.

Public Class Shoe
Public Shared Function Load() As Object
return ?????
End Function
End Class

Public Class Sandal
Inherits Shoe
End Class

Public Class MyShoeBox
Private mySandal as Sandal = Sandal.Load()
End Class

So, my question is: Is it possible to find out the type/class which was
actually called from within the base class?

Kind regards,
Roland

Jun 23 '06 #4
Roland,
| Public Shared Function Load() As Object
Ah! There's the rub!

The Load method is Shared, meaning it is part of the Shoe class, and not
inherited by the Sandal class per se.

Although VB allows you to code:

Sandal.Load()

It calls Shoe.Load directly in the IL, which means that Shoe.Load will never
know you attempted to call it on the Sandal class.

| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
If Load was an instance method (not shared) you could use Me.GetType within
it to get the actual type of the object (the derived type).
Seeing as Load is a shared method, there is no such method sans passing a
parameter.
I would consider:
1) making the Load method Generic
2) passing a Type parameter
3) adding Load to each derived type, instead of in the base class
4) create Shoe & Sandal Factory classes that allow polymorphism via
inheritance...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<ro*********@gm ail.com> wrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
| Hi,
|
| Here is the basic setup, my base class is Shoe which has a child class
| called Sandal. I would like to create objects by calling Sandal.Load.
| But without overloading Load in Sandal and sending the Sandal type to
| the base class I can not instantiate a Sandal class from within Shoe.
|
| Public Class Shoe
| Public Shared Function Load() As Object
| return ?????
| End Function
| End Class
|
| Public Class Sandal
| Inherits Shoe
| End Class
|
| Public Class MyShoeBox
| Private mySandal as Sandal = Sandal.Load()
| End Class
|
| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
|
| Kind regards,
| Roland
|
Jun 23 '06 #5
Jay,

Good catch,

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> schreef in
bericht news:Ox******** ******@TK2MSFTN GP02.phx.gbl...
Roland,
| Public Shared Function Load() As Object
Ah! There's the rub!

The Load method is Shared, meaning it is part of the Shoe class, and not
inherited by the Sandal class per se.

Although VB allows you to code:

Sandal.Load()

It calls Shoe.Load directly in the IL, which means that Shoe.Load will
never
know you attempted to call it on the Sandal class.

| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
If Load was an instance method (not shared) you could use Me.GetType
within
it to get the actual type of the object (the derived type).
Seeing as Load is a shared method, there is no such method sans passing a
parameter.
I would consider:
1) making the Load method Generic
2) passing a Type parameter
3) adding Load to each derived type, instead of in the base class
4) create Shoe & Sandal Factory classes that allow polymorphism via
inheritance...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<ro*********@gm ail.com> wrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
| Hi,
|
| Here is the basic setup, my base class is Shoe which has a child class
| called Sandal. I would like to create objects by calling Sandal.Load.
| But without overloading Load in Sandal and sending the Sandal type to
| the base class I can not instantiate a Sandal class from within Shoe.
|
| Public Class Shoe
| Public Shared Function Load() As Object
| return ?????
| End Function
| End Class
|
| Public Class Sandal
| Inherits Shoe
| End Class
|
| Public Class MyShoeBox
| Private mySandal as Sandal = Sandal.Load()
| End Class
|
| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
|
| Kind regards,
| Roland
|

Jun 23 '06 #6
Hi Jay,

Thanks for Your answer (and to all You other guys too for that matter).
Great explanation of what's happening.

Before I wrote my question I used your second suggestion of using a
Type parameter to the Load method. All class inheriting from the Shoe
class shadowed the Load method and sent GetType(Sandal) (for the Sandal
class) as parameter to Shoe.Load.

This works like a charm but it didn´t seem like a good looking
solution since all classes inheriting Shoe whould need to be modified
if I made some changes later on. Anyway I guess I stick to that for
now.

After giving it some thought I think the way I want to solve things
violates object oriented thinking since it's a kind of backward object
orientation.

Kind regards,
Roland

Jay B. Harlow [MVP - Outlook] wrote:
Roland,
| Public Shared Function Load() As Object
Ah! There's the rub!

The Load method is Shared, meaning it is part of the Shoe class, and not
inherited by the Sandal class per se.

Although VB allows you to code:

Sandal.Load()

It calls Shoe.Load directly in the IL, which means that Shoe.Load will never
know you attempted to call it on the Sandal class.

| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
If Load was an instance method (not shared) you could use Me.GetType within
it to get the actual type of the object (the derived type).
Seeing as Load is a shared method, there is no such method sans passing a
parameter.
I would consider:
1) making the Load method Generic
2) passing a Type parameter
3) adding Load to each derived type, instead of in the base class
4) create Shoe & Sandal Factory classes that allow polymorphism via
inheritance...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<ro*********@gm ail.com> wrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
| Hi,
|
| Here is the basic setup, my base class is Shoe which has a child class
| called Sandal. I would like to create objects by calling Sandal.Load.
| But without overloading Load in Sandal and sending the Sandal type to
| the base class I can not instantiate a Sandal class from within Shoe.
|
| Public Class Shoe
| Public Shared Function Load() As Object
| return ?????
| End Function
| End Class
|
| Public Class Sandal
| Inherits Shoe
| End Class
|
| Public Class MyShoeBox
| Private mySandal as Sandal = Sandal.Load()
| End Class
|
| So, my question is: Is it possible to find out the type/class which was
| actually called from within the base class?
|
| Kind regards,
| Roland
|


Jun 23 '06 #7

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

Similar topics

16
2679
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an option. Let's call the id of a class "cid" (for "class id"). The function signature should look like this: ******************************************
20
2899
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
9
5130
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:
4
9788
by: james | last post by:
I have a custom UserControl, which can have many sub class levels derived from it. I want to be able to discover all the components at Load time, but the only components I can see from the base class are the private components internal to the base class itself. What I want are ALL components for the entire class no matter how many levels of sub-classing this particular control contains. I do not want to have to force the child classes to...
3
9715
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
2
6884
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and without interfaces if need be. But try as I may they will ot unload. I have been working on this problem for weeks. I have seen other apps using Remoting but I know there has got to be a way to create a child AppDomain and reference obkect via...
6
1369
by: Michael | last post by:
Scenario: I have a base class that I want to enumerate the custom attributes of a field defined in the child of the class. Is this possible? I've tried various versions of BindingFlags on type.GetFields() but none of them retrun any fields. Thanks, Michael
10
1549
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the base class method is not to be abstract, and will be called if the instance was created as a 'generic' base class instance. It's sort of like I want the method to be abstract to children, but concrete at the base level. That way I can refer to...
0
1893
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all of my base classes including my base MDI Container form and my base MDI child form the mdi container has a singleton which returns an
0
9658
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
10533
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
10579
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
10244
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
7775
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
6975
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
5644
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
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
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.