Hi everybody
I have an abstract outer class with an inner class.
My inner class has a isValide() method which uses attributes form my
outer class.
Various sub-classes extend my outer class.
An other package contains classes which in their turn extend all these
subclasses. Let's call them SubSubClass.
Confused? - Me too ;-)
My SubSubClass contains a new attribute, which has to be validated. I
kind of would have to overwrite my isValid() method in my inner
class.
Any idea how I could do this in an "easy" way?
Thanks a lot!
Sven
An attempt to draw the "class diagram":
===========
| abstract
| OuterClass
|
| ------------------
| ¦ InnerClass
| ¦-----------------
| ¦ isValide()
| ------------------
===========
^
¦
¦
===========
SubClass
===========
^
¦
¦ other package:
¦
===========
| SubSubClass
| int newAttr;
| ------------------
| ¦ InnerClass
| ¦-----------------
| ¦ isValide()
| ------------------
===========
Andreas Leitgeb - 18 Oct 2007 13:08 GMT
> I have an abstract outer class with an inner class.
> My inner class has a isValide() method which uses attributes form my
> outer class.
> Various sub-classes extend my outer class.
> An other package contains classes which in their turn extend all these
> subclasses. Let's call them SubSubClass.
> My SubSubClass contains a new attribute, which has to be validated. I
> kind of would have to overwrite my isValid() method in my inner
> class.
One way could be that you add some getter-Method into your abstract
OuterClass, that normally returns something "valid", which is then
overridden in MySubSubClass to return it's attribute.
The inner class' isValid() then accesses the getter-method and thus
sees the derived class' attribute's value :-)
If this extra attribute really doesn't fit into the abstract outerclass'
design, it would instead need a "pluggable" Validator, and a way to
re-plug a different Validator object, which then could be actually of
type MySpecialValidator, which would then know about that extra attribute
and call it's baseClass' isValid for the other attributes.