473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to tell which base class

Supposing I have a base (abstract) class called thingBase and then I create
two more abstract classes from it, e.g. thingBase1, thingBase2.

I have code that operates on thingBase objects but I need to know whether
the object is inherited from thingBase1 or thingBase2.

How do I tell which base class was used?
Nov 20 '05 #1
3 780
* "mrrrk" <no***@xxx.yyy> scripsit:
Supposing I have a base (abstract) class called thingBase and then I create
two more abstract classes from it, e.g. thingBase1, thingBase2.

I have code that operates on thingBase objects but I need to know whether
the object is inherited from thingBase1 or thingBase2.


'ThingBase1' and 'ThingBase2' _inherit_ from 'ThingBase'?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
"mrrrk" <no***@xxx.yyy> schrieb
Supposing I have a base (abstract) class called thingBase and then I
create two more abstract classes from it, e.g. thingBase1,
thingBase2.

I have code that operates on thingBase objects but I need to know
whether the object is inherited from thingBase1 or thingBase2.

How do I tell which base class was used?


If TypeOf argument is thingBase1 then
dim thing as thingbase1
thing = directcast(thing, thingbase1)
'access type specific members here
'...
elseif typeof argument is thingBase2 then
dim thing as thingbase2
thing = directcast(thing, thingbase2)
'access type specific members here
'...
end if
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
mrrrk,
I normally use the TypeOf operator for this.

Dim thing as thingBase

If TypeOf thing Is thingBase1 Then
Dim thing1 As thingBase1 = DirectCast(thing, thingBase1)

ElseIf TypeOf thing Is thingBase2 Then
Dim thing2 As thingBase2 = DirectCast(thing, thingBase2)
End If

However this should be the exception and not the norm!!!!

If you have code that behaves differently based on thingBase1 or thingBase2,
you should consider making that code an overridable method of thingBase and
have thingBase1 & thingBase2 override the method with their own code! Which
is Polymorphism & one of the reasons for inheritance.

Hope this helps
Jay

"mrrrk" <no***@xxx.yyy> wrote in message
news:uj**************@TK2MSFTNGP10.phx.gbl...
Supposing I have a base (abstract) class called thingBase and then I create two more abstract classes from it, e.g. thingBase1, thingBase2.

I have code that operates on thingBase objects but I need to know whether
the object is inherited from thingBase1 or thingBase2.

How do I tell which base class was used?

Nov 20 '05 #4

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

Similar topics

6
by: George Styles | last post by:
Hi, I am trying to work out what a block of C++ does, but I am having trouble understanding the syntax. I know Delphi well, so am happy with objects etc, its just this syntax I dont understand. ...
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
9
by: Tony Maresca | last post by:
My class: class foo { protected virtual void MyMember() { } } When this class is a base with any number of derivatives,
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...
7
by: iwdu15 | last post by:
how can i tell if my system has gone idle? then how can i execute a command accordingly? thnks
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...
6
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
2
by: stktung | last post by:
Hey guys, Are there functions in reflection that gives information about the base classes of an object? Thanks in advance -Steve
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...
0
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...
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...

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.