21 世纪定义接口映射代码的选项
目前正在重写几个接口,并研究有哪些选项可以定义系统之间的映射。我们需要做一些事情,比如过滤掉记录,将 1 重新映射到 2 等 - 但它的核心似乎是从旧格式分配给新格式,并寻找一种清晰/易于维护的方法来做到这一点。
可能是用 Java 编写的 - 但可能会尝试加入一些 JRuby,如果这会使映射更清晰...
想到的选项是:
- 在代码中,大量 if/else 和赋值
- 通过通用系统,将映射存储在某处(例如 DB )对于简单的项目,然后
在我目前更喜欢的界面中处理它 - 使用简单分配的数组/映射,以便代码相当简洁。至少事情将是不透明的,因为映射位于代码中。预计界面不会随着时间的推移
而发生太大变化...当我写这篇文章时,我想我正在小题大做了...但既然我已经走了这么远 - 你觉得怎么样?
对于这样的事情你会做什么/你已经做了什么?
预先感谢,克里斯。
Currently working on re-writing several interfaces and looking at what options there are for defining the mapping between the systems. We need to do things like filtering out records, remap 1 into 2 etc - but the core of it seems to be assigning to the new format from the old format and looking for a nice clear/easy to maintain way to do this.
Probably written in Java - but may try and throw in some JRuby if that makes the mappings cleaner...
Options that come to mind are:
- In code, lots of if/else and assignments
- Via generic system, store the mapping somewhere (eg DB) for the easy-ish items and then just process that in the interface
I am preferring 1. at the moment - with an array/map of the simple assignments so that code is fairly succinct. And at least things will be opaque as the mapping is in the code. Its anticipated that the interface will not change much over time...
As I write this, I am thinking I am making a mountain out of a mole hill... but since I have gone this far - what do you think?
What would you do/have you done for things like this?
Thanks in advance, Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在回到选项 2 - 将简单映射存储在配置文件/数据库中(可能以 DSL 格式),以便将来需要更改时轻松访问。
Swinging back towards option 2 now - storing the simple mappings in a config file/db (perhaps in a DSL format) for ease of access if a change is needed in future.