开发者

class definition dependence on runtime

in my webapp I made two different sessionhandler classes开发者_开发知识库 inheriting from a class called SessionHandler

Now I'd like to initiate the appropriate handler (dependent on a cookie value.)

Background: My SessionHandler should be the base class of the Controller as it needs to call a Controller backend method otherwise i would assign the handler object to a ctrl member

Is there a way to set the superclass at runtime?

Or other way to solve that? Hope you got what i meant!


I am not sure I entirely understood your question, but are you sure you need to use inheritance? Couldn't the class you need just be a member instead?

Changing the superclass at runtime does not sound like a very good design, if at all possible.

Just to be sure I got you, what you want to do is have Controller inherit from one of the SessionHandlers, but select which one at runtime? I would rather make Controller have a member variable of type SessionHandler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜