lundi 12 octobre 2015

Create an object of class implementing an interface with

I wrote an interface

public interface IWorker<T> {}

And then implementations

public class FooWork implements IWorker<FooArgs> {}
public class BarWork implements IWorker<BarArgs> {}

During runtime, I might get different "Args", say either FooArgs or BarArgs. I have to find the concrete implementation of IWorker that uses respective Args class.

Right now am using a WorkerFactory to get the worker instance using a switch case. As you know, I have to alter this class to add new implementation.

Friends, shed some light to do this in runtime using reflection.





Aucun commentaire:

Enregistrer un commentaire