473,322 Members | 1,540 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,322 software developers and data experts.

Inheritance Question

Hi,

I have a base class with a method that need to determine which derived class
(child class) called it. How can I do this?

Thanks
Nov 15 '05 #1
6 2008
"Eric" <no****@hotmail.com> wrote in
news:#d**************@TK2MSFTNGP09.phx.gbl:
Hi,

I have a base class with a method that need to determine which
derived class (child class) called it. How can I do this?


Eric,

"this" is the instance of the calling class, and "this.GetType()"
will return the type of the calling class.
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #2
Hi Eric,

Though you can do as Chris describes, you might like to consider whether you
have correctly encapsulated your child class functionality. Code that
explicitly examines type can often be generalised via a virtual method.

Cheers

Doug Forster

"Eric" <no****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a base class with a method that need to determine which derived class (child class) called it. How can I do this?

Thanks

Nov 15 '05 #3
Doug Forster wrote:
Hi Eric,

Though you can do as Chris describes, you might like to consider whether you
have correctly encapsulated your child class functionality. Code that
explicitly examines type can often be generalised via a virtual method.

Cheers

Doug Forster

"Eric" <no****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a base class with a method that need to determine which derived


class
(child class) called it. How can I do this?

Thanks


I agree. If you need to find the "derived" class from a base class, you
have something in base class that is not generalized enough. If you can,
you might want to also attempt delegation pattern instead of inheritence
which gives you better control over things.

Or wait till generics come out. If its implemented in any manner like
VC++, you can probably use the great ATL trick of using the child class
as an input template argument..

--
Girish Bharadwaj

Nov 15 '05 #4
Thanks for all your posts. I will have to look at my design and see if I
can change it. Here is what I am doing: I have a overrided method called
for each derived class and in each class which does something particular to
the derived class and it then needs to call a method in base which needs to
know which derived class called it.

Thanks

"Girish Bharadwaj" <girishb@nowhere> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Doug Forster wrote:
Hi Eric,

Though you can do as Chris describes, you might like to consider whether you have correctly encapsulated your child class functionality. Code that
explicitly examines type can often be generalised via a virtual method.

Cheers

Doug Forster

"Eric" <no****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a base class with a method that need to determine which derived


class
(child class) called it. How can I do this?

Thanks


I agree. If you need to find the "derived" class from a base class, you
have something in base class that is not generalized enough. If you can,
you might want to also attempt delegation pattern instead of inheritence
which gives you better control over things.

Or wait till generics come out. If its implemented in any manner like
VC++, you can probably use the great ATL trick of using the child class
as an input template argument..

--
Girish Bharadwaj

Nov 15 '05 #5
Eric wrote:
Thanks for all your posts. I will have to look at my design and see if I
can change it. Here is what I am doing: I have a overrided method called
for each derived class and in each class which does something particular to
the derived class and it then needs to call a method in base which needs to
know which derived class called it.

Thanks

"Girish Bharadwaj" <girishb@nowhere> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Doug Forster wrote:

Hi Eric,

Though you can do as Chris describes, you might like to consider whether
you
have correctly encapsulated your child class functionality. Code that
explicitly examines type can often be generalised via a virtual method.

Cheers

Doug Forster

"Eric" <no****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl. ..
Hi,

I have a base class with a method that need to determine which derived

class
(child class) called it. How can I do this?

Thanks


I agree. If you need to find the "derived" class from a base class, you
have something in base class that is not generalized enough. If you can,
you might want to also attempt delegation pattern instead of inheritence
which gives you better control over things.

Or wait till generics come out. If its implemented in any manner like
VC++, you can probably use the great ATL trick of using the child class
as an input template argument..

--
Girish Bharadwaj



That sounds like (sorta) Visitor pattern. You might want to look up that
pattern and see if that might help you out in your design.

--
Girish Bharadwaj

Nov 15 '05 #6

HI Eric,

Has your problem been resolved?
If you still have any unclear, please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Eric" <no****@hotmail.com>
| References: <#d**************@TK2MSFTNGP09.phx.gbl>
<Oy**************@TK2MSFTNGP10.phx.gbl>
<uh**************@TK2MSFTNGP10.phx.gbl>
| Subject: Re: Inheritance Question
| Date: Fri, 17 Oct 2003 09:23:26 -0600
| Lines: 54
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OW**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:192106
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for all your posts. I will have to look at my design and see if I
| can change it. Here is what I am doing: I have a overrided method called
| for each derived class and in each class which does something particular
to
| the derived class and it then needs to call a method in base which needs
to
| know which derived class called it.
|
| Thanks
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:uh**************@TK2MSFTNGP10.phx.gbl...
| > Doug Forster wrote:
| >
| > > Hi Eric,
| > >
| > > Though you can do as Chris describes, you might like to consider
whether
| you
| > > have correctly encapsulated your child class functionality. Code that
| > > explicitly examines type can often be generalised via a virtual
method.
| > >
| > > Cheers
| > >
| > > Doug Forster
| > >
| > > "Eric" <no****@hotmail.com> wrote in message
| > > news:%2****************@TK2MSFTNGP09.phx.gbl...
| > >
| > >>Hi,
| > >>
| > >>I have a base class with a method that need to determine which derived
| > >
| > > class
| > >
| > >>(child class) called it. How can I do this?
| > >>
| > >>Thanks
| > >>
| > >>
| > >
| > >
| > >
| > I agree. If you need to find the "derived" class from a base class, you
| > have something in base class that is not generalized enough. If you can,
| > you might want to also attempt delegation pattern instead of inheritence
| > which gives you better control over things.
| >
| > Or wait till generics come out. If its implemented in any manner like
| > VC++, you can probably use the great ATL trick of using the child class
| > as an input template argument..
| >
| > --
| > Girish Bharadwaj
| >
|
|
|

Nov 15 '05 #7

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

Similar topics

1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
2
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
4
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error...
8
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
5
by: Noah Roberts | last post by:
Is there anything that says that if you virtually inherit from one class you have to virtually inherit from anything you inherit from?
3
by: RSH | last post by:
I have a simple question regarding inheritance in a web form. I have a DropDownList in an aspx form. It is called DropDownList1 I have a class that will be overriding the render event so I...
8
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.