This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes super.super.method() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super.super.method()" Watch "super.super.method()" New topic


Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Is there a way to call a method from two levels up the inheritance heirarchy (where at each level the particular method is overridden and without instantiating any of the parent classes)?
So, if we have these three classes:

Thank You

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Let me also add that if you find yourself in a situation where that's what you want to do in your code, that's a big red flag that your design is flawed.
It means, in your subclass of the "grandparent", (the middle one) you factored out some functionality that you now want to re-implement in the grandchild class (the last one). This immediately suggests to me you flatten out your hierarchy, making the bottom most class a subclass of the grandparent. There may be other refactorings as well, but this is the one that LEAPS out at me when I get asked this question.
ie, go from this:

to this:

[ February 28, 2002: Message edited by: Rob Ross ]
[ February 28, 2002: Message edited by: Rob Ross ]

SCJP 1.4
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
That's what I'd figured. Thanks Rob.
[ February 28, 2002: Message edited by: Dirk Schreckmann ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: super.super.method()
jQuery in Action, 3rd edition