This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Originally posted by Anil Kumble: now two struts classes cat and dog both come to Bone action. and Bone action class 'stuffToDoBeforePage' will contain everything needed to be done before bone.jsp is shown.
That doesn't sound too terrible, though it sounds like a struts 1 way to go about it. Have you thought about using an interceptor that both cat and dog would be configured to use? How about making cat and dog both subclasses of a pet class that contains stuffToDoBeforePage?
but both cat and dog are extending ActionSupport. Should the pet class extend ActionSupport and then cat and dog extend pet class and have their overwrite the 'execute()' method? then when both cat and dog are about to pass control over to bone.jsp they call the method in pet class which does 'stuffToDoBeforePage'.
That sounds like it would work fine. I usually do something like this (not exact Java, error handling overlooked):
This gives you a little insurance that you won't accidentally delete the "stuffToDoBeforePage" invocation in the subclass and kill your app, plus it's a little more "object oriented" in that the subclass doesn't know much about the superclass.
Joined: Jun 04, 2007
Thanks, that looks much better and very OO.
Have one last question though. I assume an abstract class can only 'define' methods and not write their body right? or i might be wrong.
If I am right then I'll have to write doSuperclassTask in both of my subclasses. and it will basically contain the same thing.
If I'm wrong (i hope i am) then this will work great.
I know, I'm forgetting my basic java OO principals here
edit; just saw that you declared subclasstask as abstract. so methods with keyword 'abstract' wont have a body. others can. [ December 10, 2007: Message edited by: Anil Kumble ]