Class inside another class

  • Thread starter Thread starter Alper Barkmaz
  • Start date Start date
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
 
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.
 
Back
Top