By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,708 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,708 IT Pros & Developers. It's quick & easy.

Accessing Owner class instance possible?

P: n/a
Hello,

I have a class inside another class. The Scenario is like Car->Engine, where
Car is a class with a set of properties and methods and Engine is another
class inside it with its own set of properties.

I want to know if there is a way to access the methods and the properties of
the Owner class for the class that's inside it? I.e. I want to find out
within Engine what make the Car is which is exposed by the property
Car.Model.

Is there any way I can do that?

:) Thanks for reading.

Cheers
Cyril Gupta
Jan 4 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Cyril Gupta" <no****@mail.com> schrieb:
I have a class inside another class. The Scenario is like Car->Engine,
where Car is a class with a set of properties and methods and Engine is
another class inside it with its own set of properties.

I want to know if there is a way to access the methods and the properties
of the Owner class for the class that's inside it? I.e. I want to find out
within Engine what make the Car is which is exposed by the property
Car.Model.


You will have to pass a reference which points to the 'Car' instance to the
'Engine' class instance.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 4 '06 #2

P: n/a
Cyril,

The class is only a template.

You use the object.

So in my opinion should there be as there is a
Car.Engine as well a Car.Mark

If you have done
dim myEngine as Car.Engine
Than the myEngine is normally if you have not done something extra as done
in a datarow an individual object.

In a datarow there is a special property DataTable, which tells to which
datatable a datarow belongs.

However that is an extra property in the Class of the datarow.

I hope this helps,

Cor
Jan 4 '06 #3

P: n/a
Hi, Cyril,
Ultimately, having a class defined inside another class primarily impacts two things: the way you refer to the nested class (i.e., fully qualified from the outside world, though not to the enclosing class), and the permissions that the nested class ultimately exposes to the outside world (which are throttled by the access of the enclosing class). Beyond that, the internal class simply works like any other class. The outer class still needs to have member variables which reference that class, and the internal class would likewise need member variables to refer back to the enclosing class (if such was needed).

Personally, I always try to avoid using internal classes which need to refer back to enclosing classes -- if such commerce is always going to be required, then it's not clear why there would be a benefit to factoring code in that fashion in the first place. (In general, I try to avoid such back-references between *any* two classes, regardless of nesting, but sometimes that's not always possible and in any event is beside the point.)

There's more information on nested classes at http://msdn.microsoft.com/library/de...components.asp which discusses the circumstances under which nested class usage makes sense.

Hope this helps!
--Matt--*

-----Original Message-----
From: Cyril Gupta
Posted At: Wednesday, January 04, 2006 8:26 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accessing Owner class instance possible?
Subject: Accessing Owner class instance possible?
Hello,

I have a class inside another class. The Scenario is like Car->Engine, where
Car is a class with a set of properties and methods and Engine is another
class inside it with its own set of properties.

I want to know if there is a way to access the methods and the properties of
the Owner class for the class that's inside it? I.e. I want to find out
within Engine what make the Car is which is exposed by the property
Car.Model.

Is there any way I can do that?

:) Thanks for reading.

Cheers
Cyril Gupta
Jan 4 '06 #4

P: n/a
Hello Matthew,

Thank you for pointing me to that article, it was quite helpful. I am not
pleased with this either, but it has become important in the context of my
software.

Till now I have avoided referring to the owner class, let's hope I can
continue doing that.

Thanks for helping :)

Cyril Gupta
Jan 5 '06 #5

P: n/a
Yep, that should do it

I guess I can do that when I create an instance of the nested class. Thanks
for the tip

:)

Regards
Cyril Gupta
Jan 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.