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.
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 Node
s 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.
精彩评论