-
June 14th, 2002, 06:58 AM
#1
nesting of classes and inheritance
What is the use of nested classes?
My doubt is whatever a nested class provides is provided by inheritance. But whatever inheritance provides is not provided by nested classes(such as run time polymorphism and virtual functions). Also imparting properties of a class to another classes through inheritance is easier than using nested classes.
Why then we need nested classes?
-
June 17th, 2002, 01:48 PM
#2
Nesting classes provide versitility just like inheritance does but it isn't the same kind of versitility.
If you had a hammer tool class then your hammer tool class could make use of all different' types of nail classes as well as perhaps some screw classes. Here your nail classes might all inherit their hammer interface from a parent class but that parent class wouldn't be a hammer. Get it?
Can think of many examples but the basic truth is you can probable make due with Inheritance without nesting classes for some logic problems. But having both relationships availible and the knowledge of how and when to use both will enable you to write clearer more understandable and maintainable code.
Objects can have different types of relationships to each other. Some objects are made up of other objects, like a house made of bricks. And some objects which don't exist at the same time can still be associated to each other through inheritance.
It's the clasic "is a" or "has a" paradiam.
-
June 18th, 2002, 10:27 AM
#3
Excuse my ignorance, but...
Is there another word for "nested class" I haven't read about this concept in those words.
Martin Breton
3D vision software developer and system integrator.
-
June 18th, 2002, 11:06 AM
#4
Another name for nested class is "has a". In object orienented terminalogy what he is describing is the difference between "is a" and "has a". A horsie "is a" mamal. A horsie "has a" tail.
-
June 18th, 2002, 11:30 AM
#5
Re: Excuse my ignorance, but...
Originally posted by proxima centaur
Is there another word for "nested class" I haven't read about this concept in those words.
I don't know about another name. I have heard his name already for the same concept. It is just the definition of a class inside another class.
It is not always very nice to read such a code as the definition of the class is bigger, but the concept is interesting and can lead to a conception easier to read.
Elrond
A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
-- George Steiner
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|