Anil Philip
Posts: 19
Nickname: anilphilip
Registered: Nov, 2002
|
|
Re: impossible to create a Factory Method in Java?
|
Posted: Nov 6, 2002 12:17 PM
|
|
> Hi Anil, > > I don't think the factory method is supposed to be > implemented as a static. Then you lose the whole > advantage of the factory method pattern, i.e., let > polymorphism choose the correct implementation of the > factory method. Polymorphism doesn't work with static > methods. > > What you want instead is an instance method on some other > object, for example, if you have some notion of a > TaskManager. If there isn't a natural place for that > instance method to live, then, well... are you sure you > want a Factory Method? Maybe you just want a Factory. > > -jmc
Yes, I have a TaskManager server that accepts requests via socket and performs tasks (rather like a simple webserver). However I require that new kinds of tasks "new services" be painlessly added to the task server (like in the Interceptor pattern). They just need to register themselves for callback, and to implement a task interface. Task Manager should be able to invoke doWork() on a task and if there are fewer task objects than requests, to clone a task for the pool.
|
|