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

access to subclass properties

Hello everyone.

I have an abstract class named Person. I also have a class that inherits
from Person which is named Client.

When I instantiate these as follows:

Dim nuClient as Person
nuClient = New Client

I do not get access to the properties and methods of class Client in VS2003
because the variable is of type Person.
I understand that if I have a Client property that overrides a Person
property, that the Client property or method will be the one that is
executed. This is what I want. However I also want access to the other
Client properties and methods.

What do I need to do to have access to Client's properties and methods?
Change the Person class so that it is not abstract but inheritable?

Thank you for your help.

-Mark

Nov 21 '05 #1
3 1536
"Mark Petruszak" <mp******@newsgroup.nospam> wrote in message news:BE**********************************@microsof t.com...
Dim nuClient as Person
nuClient = New Client : : What do I need to do to have access to Client's properties and methods?


It's called a typecast.

CType( nuClient, Client).ClientOnlyMethod( "123-45-6789")

The CType conversion function changes nuClient (of type Person) into an
object of type Client for purposes of the ensuing call to ClientOnlyMethod( )
which I'm assuming doesn't exist on base class Person.

If nuClient turns out not to actually be a Client -- then CType( ) will throw
an InvalidCastException.
Derek Harmon
Nov 21 '05 #2
Thank you Derek, I hadn't thought of type casting. I'll give it a whirl.

Your assupmption was correct. There are properties and methods peculiar to
Client which don't exist in Person.

Thank you for your help.

"Derek Harmon" wrote:
"Mark Petruszak" <mp******@newsgroup.nospam> wrote in message news:BE**********************************@microsof t.com...
Dim nuClient as Person
nuClient = New Client

: :
What do I need to do to have access to Client's properties and methods?


It's called a typecast.

CType( nuClient, Client).ClientOnlyMethod( "123-45-6789")

The CType conversion function changes nuClient (of type Person) into an
object of type Client for purposes of the ensuing call to ClientOnlyMethod( )
which I'm assuming doesn't exist on base class Person.

If nuClient turns out not to actually be a Client -- then CType( ) will throw
an InvalidCastException.
Derek Harmon

Nov 21 '05 #3
"Mark Petruszak" <mp******@newsgroup.nospam> wrote in message
news:BE**********************************@microsof t.com...
I have an abstract class named Person. I also have a class that
inherits from Person which is named Client.

When I instantiate these as follows:
Dim nuClient as Person
nuClient = New Client

I do not get access to the properties and methods of class Client
in VS2003 because the variable is of type Person.
Correct. Your code states that you wish to treat this object as
the more generic "Person" type, not as the "Client" type. So 'Studio
only gives you access to the Person Properties, Methods, etc.
What do I need to do to have access to Client's properties and
methods?
The simplest way is to put the object into a variable of type Client;
then you can "do" Client things with it.

Dim nuPerson as Client

If you need to do both Person /and/ Client things, your code gets a
little messier, as in

Dim nuClient as Person
nuClient = New Client

nuClient.PersonMethod()
DirectCast( nuClient, Client ).ClientMethod()
Change the Person class so that it is not abstract but inheritable?


Your class definitions are fine as they are.

HTH,
Phill W.
Nov 21 '05 #4

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

Similar topics

0
by: flupke | last post by:
I have the following test code setup, trying to get the class name of a subclass in the super class. (Reason why i want this is described below) file class_name_start.py ========================...
4
by: Angelos Karantzalis | last post by:
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. ...
3
by: Larry Lard | last post by:
Hi, This seems to me like a problem that has a simple solution but I can't for the life of me work it out. Suppose I have a base class Employee Public Class Employee Public FullName As...
5
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to...
2
by: bryan | last post by:
Hi all, I am developing a web app in .net 2.0. I have a few DropDownLists that are used on multiple web forms, these show shop locations and employees. Each DDL is placed inside a...
6
by: wingphil | last post by:
Hi there, I have a shared method in a base class, and I need to know which subclass it has been called from. So for example Public Mustinherit Class BaseClass Public Shared Sub SharedMethod...
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
4
by: RinKaMeAri | last post by:
Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method():
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...

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.