473,586 Members | 2,555 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 3616
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
2662
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
2872
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
5114
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
9769
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...
3
9686
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...
2
6864
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...
6
1352
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
1529
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...
0
1863
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
7912
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...
0
7839
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...
0
8202
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. ...
0
8338
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...
1
7959
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...
0
8216
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...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.