(Newbie) Inheritance of a base class

  • Thread starter Thread starter Darren.Ratcliffe
  • Start date Start date
D

Darren.Ratcliffe

Hi Everyone

I was wondering if you could help me. In short, I would like to know
how I can do the folloing from VB.NET in C#:

Private m_CurrentItem As Product

(this will give me an instance of my Product class.

Here's the long-winded version.

I am using a base-class "Visit" for my application which will then
contain instances of classes below it (i.e. XmlBuilder and PkgAvail).


What I would like to do is confugure a number of public variables (or
proteceted?) which can be set in my .aspx by Visit.Configure(x,y,z).
Then in my XmlBuilder class, I want to access the pubilc variables that
I have defined in my Visit class.

Does that make any sense?

I am largely finding my feet with some of the more advanced OO stuff,
so I am sorry if it doesn't make too much sense!

Many many thanks in advance!

Daz
 
Your explanation is a little fudgy, but I'll give it a shot.

Work with your Visit class first, and get it correct.

You can either expose the sub objects (XmlBuilder for instance) as a
property of the Visit class,
OR you can hide the XmlBuilder class, and present properties / methods to
alter an internal instance of the XmlBuilder class.

public class Visit
{
public XmlBuilder MyExposedXmlBuilder
{
get ( return this.m_instanceOfAnXmlBuilder; }
}
}

OR

public class Visit
{
public string PropertyOfXmlBuilderButHidden
{
set
{
if (null!=this.m_instanceOfAnXmlBuilder)
{
this.m_instanceOfAnXmlBuilder.FirstName = value;
}
}
}
}

Naturally,t here is no "firstname" property, but its any property of
xmlbuilder you want to expose.

...

After you get Visit working the way you want it to.

On the code behind of the aspx page (.cs or .vb)

you'll need a member variable

private m_myVisit = null;


and a property (of the code behind page)

public Visit TheVisitAsAAspxProperty
{
get ( return this.m_myVisit;)
set ( this.m_myVisit = value);
}

Somewhere (in the page_load probably) you'll need to instantiate m_myVisit.

...


maybe that helps, maybe not.

You should describe what you're trying to .. outside of your idea to do it,
... and then present your idea for handling it.
 
Your explanation is a little fudgy, but I'll give it a shot.

Work with your Visit class first, and get it correct.

You can either expose the sub objects (XmlBuilder for instance) as a
property of the Visit class,
OR you can hide the XmlBuilder class, and present properties / methods to
alter an internal instance of the XmlBuilder class.

public class Visit
{
public XmlBuilder MyExposedXmlBuilder
{
get ( return this.m_instanceOfAnXmlBuilder; }
}
}

OR

public class Visit
{
public string PropertyOfXmlBuilderButHidden
{
set
{
if (null!=this.m_instanceOfAnXmlBuilder)
{
this.m_instanceOfAnXmlBuilder.FirstName = value;
}
}
}
}

Naturally,t here is no "firstname" property, but its any property of
xmlbuilder you want to expose.

...

After you get Visit working the way you want it to.

On the code behind of the aspx page (.cs or .vb)

you'll need a member variable

private m_myVisit = null;


and a property (of the code behind page)

public Visit TheVisitAsAAspxProperty
{
get ( return this.m_myVisit;)
set ( this.m_myVisit = value);
}

Somewhere (in the page_load probably) you'll need to instantiate m_myVisit.

...


maybe that helps, maybe not.

You should describe what you're trying to .. outside of your idea to do it,
... and then present your idea for handling it.


You're throwing around the term "base class" ,but I'm not sure you're really
understanding what a base class is.
 
Hi Sloan

Thanks for the help depite my dodgy explanation!

I'll try to explain what I am trying to do a little better - being new
to this means that I'm also finding it a bit difficult to explain.
Here's a hypothetiacal situation loosely based on what I want to do -
I've tried to bullet it point by point to make it easier to follow.

1) I am writing some code that accesses a generic booking system.

2) The way I wanted to set up my class/dll is so that we have a base
class called Visit.cs.

3) From Visit.cs, you can access instances of Cars.cs, Trains.cs and
Planes.cs

4) These classes access different data sources to retun the information
(as XML).

5) Each datasource has a common username and password which I want to
store in my Visit class and refer back to from each child class.

6) The username and password are set from Visit.Configure(...), and
they are stored in protected(?) variables/properties so that they are
accessible to Cars.cs, Trains.cs and Planes.cs but not in my aspx pages
(for the arguments sake).

7) I am fine at setting up things like public Cars Cars = new Cars();
in my Visit class.

8) What I want to know is, in Cars.cs how do i reference the protected
properties of my Visit object?

I suppose what I am looking to do is pass an instance of the Visit
object through to the child class so I can access values stored within
it.

Hopefully I have made a better job of explaining myself.

Many many thanks, I really appreciate it.

Darren
 
Hi Marc, and to everyone else.

Well, after a good hour and a half of brushing up on OOP with Pro C#
2005 and the .NET 2.0 Platform (Apress) that I bought, I have got it.

What I want to do is set up my child class (train) as train:vehicle.

Then, I can access the protected properties of animal from within
trainby doing this.VehicleProperty.

Now I know that, even I think I sounded stupid before ;)

Many thanks for all your help - it is appreciated :)
 
Back
Top