Nested Classes or Alternative?

  • Thread starter Thread starter Rudolf Ball
  • Start date Start date
R

Rudolf Ball

Hi NG,

I want to build two classes,

Demo.Car (where Demo is the Namespace) and
Demo.Car.Wheel

Is the only solution a nested Class? Isn`t there anything more elegant?

Thank you

Rudi
 
Hi Rudi,
I want to build two classes,

Demo.Car (where Demo is the Namespace) and
Demo.Car.Wheel

Is the only solution a nested Class? Isn`t there anything more elegant?

What do you say about:
Demo.CarParts.Wheel (where "Demo.CarParts" is the namespace) ?

Usually the nested classes are those classes which instances
lives only in their "main class" object, and are initialized
usually by "main class".

In your case word "elegant" should replaced with "functional".

Regards

Marcin
 
You can use reference wich points to our class, but why you need it? Why not
to make Wheel Property of Car of Wheel type???
namespace Demo
{
class Car
{
Wheel m_wheel;
public Wheel Wheel
{
get {return m_wheel;}
set {m_wheel = value;}
}
}
}

Now you can use
Demo.Car.Wheel = new Weel(whatever);
Demo.Car.Wheel.Tyre = new Tyre(TyreTypes.Michelin); // :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top