Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Abstract class with Inner class - Inheritance (http://www.velocityreviews.com/forums/t545179-abstract-class-with-inner-class-inheritance.html)

sven.furrer@gmail.com 10-18-2007 09:10 AM

Abstract class with Inner class - Inheritance
 
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 10-18-2007 12:08 PM

Re: Abstract class with Inner class - Inheritance
 
sven.furrer@gmail.com <sven.furrer@gmail.com> wrote:
> 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.



All times are GMT. The time now is 01:38 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.