Class inside another class

A

Alper Barkmaz

Hello;

While examining Microsoft's Framework Class Tree, i saw many classes
under another class; for example treeviewnode class appears to be
under treeview class.

I wonder why it is used, it should be having benefits to code like
this.

Thank you very much
 
E

Edward G. Nilges

Hello;

While examining Microsoft's Framework Class Tree, i saw many classes
under another class; for example treeviewnode class appears to be
under treeview class.

I wonder why it is used, it should be having benefits to code like
this.

Thank you very much

It simplifies the design of both classes, and the subclass might be
useful on its own. In some cases the subclass is all that is needed,
and you don't want the user to have to load the superclass AND the
subclass.

Also, when a class logically consists of a collection of things, you
need to expose a standalone way to examine one "thing" in isolation.
Otherwise, everytime you need to get to one thing using the
superclass, you'd have to provide an index to the target.

In the case of treeview, that index would be a very complex position
in the tree.
 

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

Top