hi -
i understand super passes method calls up to the parent.
is there a way to call down to the child instance, to a different
method?
I realize i could pass a function block up to super, and then use
yield to call back to the child, but i want to hide this complexity
from my child classes.
the setup is something like this:
class Webserver < HTTPServlet::AbstractServlet
def do_GET(request, response)
// here i want to hand off to the instance child servlet to
handle the response
child.render()
end
end
class Servlet1 < Webserver
def render
// do some stuff
end
end
etc for other servlets.
I guess the other way is to instantiate the right child servlet in the
webserver, but this means i dont get access to super methods…
tx,
/dc
David "DC" Collier
mailto:[email protected]
+81 (0)80 6521 9559
skype: callto://d3ntaku
“dc” typed:
i understand super passes method calls up to the parent.
is there a way to call down to the child instance, to a different method?
I guess the other way is to instantiate the right child servlet in the
webserver, but this means i dont get access to super methods…
My OO know-how may have turned rusty, but isn’t a Parent class (and
therefore its object) oblivous of its children (and therefore the
methods
and whatever defined in its children)?
Why not re-define do_GET in Servlet1?
–
Ayaz Ahmed K.
“Not only is this incomprehensible, but the ink is ugly and the paper
is from the wrong kind of tree.”
– Professor W.
On 12/16/06, dc [email protected] wrote:
the setup is something like this:
class Webserver < HTTPServlet::AbstractServlet
def do_GET(request, response)
// here i want to hand off to the instance child servlet to
handle the response
child.render()
end
end
Just (re)define render in the child. Example:
$ irb
irb(main):001:0> class Webserver
irb(main):002:1> def get
irb(main):003:2> puts “In superclass”
irb(main):004:2> render
irb(main):005:2> end
irb(main):006:1> def render
irb(main):007:2> puts “In superclass#render”
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> class Servlet < Webserver
irb(main):011:1> def render
irb(main):012:2> puts “In subclass#render”
irb(main):013:2> end
irb(main):014:1> end
=> nil
irb(main):015:0> Servlet.new.get
In superclass
In subclass#render
But remember, a superclass doesn’t know about its subclasses.