开发者

Runnable subclasses, ordinary superclass, how to run the subclasses?

Mind you, my design could be wrong completely so I'd accept any advice on that too.

I have a Network (a container of my own) and nodes in the net, but nodes can be routers or clients, so I have a node class that has various setters and getters common to any node, and Node is extended by Client and Router.

开发者_JAVA百科

Now I have to start the nodes in their own threads, but Node is not runnable, that's one of the main differences between Routers and Clients, so these subclasses are implementing Runnable and have their own different neat run() methods.

The component starting up the nodes can call on Nodes using the Network.

So how can I start/run the subclasses?


If Router and Client both implement Runnable, you could make Node implement Runnable at a higher level. Node's run() method could either be a no-op, or you could make run() abstract in Node, to force the subclasses to implement it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜