Re: anonymous derived class
On Apr 9, 6:57 am, "Gaijinco" <gaiji...@gmail.com> wrote:
I have always felt that there are a lot of topics that you learned the
facts but you only grasp the matter sometime down the road.
For me, two of those topics are inner classes and anonymous classes.
Are you sure you're posting to the right group. C++ doesn't
have anonymous classes at all, and it usually uses the term
"nested class", rather than "inner class" (and nested classes in
C++ don't have quite the same semantics as inner classes do in
Java).
I was thinking of a class Agenda. For it I would use a class Person
which also uses another class Date for her birthday.
When I was modeling Person, I made an atribute to be an object of
class Date. Suddenly I thought that maybe it was a good idea to made
it an inner classes.
Why? Regardless of the language or the exact semantics of
inner/nested classes, I can't imagine ever making Date depend in
any way on Person.
But then I supossed it would be even better to
make it an inner derived class.
Why? And derived from what.
But to make it easier to acces members
of the inner class I made it annonymous.
Access what members? I'd say that there is a serious problem
with your design if Date has to start accessing members of
Person.
Is this good practice?
No.
Does it makes sense?
No.
What good uses of inner
classes and anonymous classes do you know?
I use nested classes in C++ when the class is an implementation
detail of the outer class, or an intrinsic part of the outer
class' interface. I use inner and anonymous classes in Java
when I want to confuse the reader, and make it more difficult to
understand my code. (Actually, I usually use them to work
around the lack of working multiple inheritance. But they're
very good for obfuscation as well.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34