I would like to have design suggestion for t开发者_运维技巧he following issue:
I am programming for server application.(JBOSS)
It's something very common, but I am not sure how to implement this.
I am implementing an Interface.
each class which implements that interface will have different implementation.
in the future, I am sure that I will need to add more implementations, which means I will need to add additional "new" to my code.
How can I separate the "new" allocations to a different file/package/ear/jar, so if in the future I will have to add additional implementations for this specific interface, I wont need to open the whole source code.
I want to make it plug-ability, as much as I can.
thanks,
ray.
It sounds like you're looking for dependency injection.
If you code to the interface instead of the implementation (which you should be doing anyway) then you can use dependency injection to specify the implementation details by configuration. This is a fairly common technique when using Spring.
When you later decide to use a new implementation, the implementing classes can be put in their own jar, added to your application and the dependency injection configuration can be changed.
精彩评论