单独实现编程设计
我想对以下问题提出设计建议:
我正在为服务器应用程序编程。(JBOSS)
这是很常见的事情,但我不确定如何实现它。
我正在实现一个接口。
每个实现该接口的类都会有不同的实现。
将来,我确信我需要添加更多实现,这意味着我需要向我的代码添加额外的“新”。
如何将“新”分配分离到不同的文件/包/ear/jar,因此,如果将来我必须为此特定接口添加其他实现,我不需要打开整个源代码。
我想让它尽可能地具有可插入性。
谢谢,
雷。
I would like to have design suggestion for the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您正在寻找依赖注入。
It sounds like you're looking for dependency injection.
如果您对接口而不是实现进行编码(无论如何您都应该这样做),那么您可以使用依赖项注入通过配置指定实现细节。这是使用 Spring 时相当常见的技术。
当您稍后决定使用新的实现时,可以将实现类放入它们自己的 jar 中,添加到您的应用程序中,并且可以更改依赖项注入配置。
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.