Abstract class with Inner class - Inheritance

S

sven.furrer

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()
| ------------------
===========
 
A

Andreas Leitgeb

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top