使用特定于版本的存根
我的项目基于客户端和服务器通信,其中在不同位置,可能存在不同版本的服务器。 客户端根据最近的服务器版本号使用特定的存根文件与其通信。
现在,在编写代码时,在我使用存根的每个地方,我都必须检查存在哪个版本的服务器。这看起来效率很低,因为代码中有很多地方我必须检查存根版本。
限制是客户端周围只有一台服务器。一旦客户端启动,它要通信的服务器就不会改变。 为了进行通信,我们使用 Jax RPC。
有更好的设计建议吗?
My project is based on client and server communication in which at different locations, different version of server may be present.
Client, based on nearest server's version number uses specific stub file to communicate with it.
Now, while writing the code, at every place where i'm using the stub, i've to check which version of server is present. This seems very inefficient because there are many places in the code, where i've to check stub version.
The constraint is that exactly one server is present around the client. And once client has started, the server to which it is going to communicate will not change.
For communication we are using Jax RPC.
Any suggestions for better design?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
依赖注入在这里有帮助吗?将特定于每个服务器版本的所有逻辑隔离到单独的类中,并使用 Google Guice 将所有特定服务器版本类组织到它们自己的模块中(即每个服务器版本一个模块)。然后,一开始只需要进行一次检查即可确定要加载哪个模块。
Could dependency injection help here? Isolate all the logic specific to each server version into separate classes and use a tool such as Google Guice to organize all your specific server version classes into their own modules (i.e. one module per server version). Then, only one check would be required at the beginning to see which module to load.