从两个角度对域进行建模
我正在尝试对我的系统域进行建模,但我遇到过问题并需要一些帮助。
我的问题是一种观点。我正在建模一个系统,其中有一个客户实体,该实体将有许多订单实体,并且系统需要列出所选客户的所有订单(视角 1)。因此,我建模了一个 Customer 类,其中包含 Orders 的集合......很简单。然而,我刚刚意识到系统还需要列出所有订单以及客户的详细信息(视角 2),这意味着我从每个订单都有一个客户参考。
问题是,从每个角度来看,我将花时间创建我不感兴趣的对象,例如,当我显示订单列表时,将为每个订单创建一个 Customer 实例;反过来,Customer 实例将保存他们所做的订单的集合(从这个角度来看我对此不感兴趣!)。
有人可以帮忙提供建议吗?我以前遇到过这个问题,但我从未花时间设计一个合适的解决方案。
问候,
JLove
I'm trying to model the domain of my system but I've come across and issue and could do with some help.
My issue is one of perspective. I'm modeling a system where I have a Customer entity which will have a number of Order entities and the system will be required to list all the Orders for a selected Customer (perspective 1). I therefore modeled a Customer class which contains a collection of Orders... simple. However I've just realised that the system will also need to list all Orders with the details of the Customer (perspective 2) which would mean that I had a single Customer reference from each Order.
The problem is that from each perspective I will be taking time to create object which I will not be interested in E.g. When I will display a list of Orders a Customer instance will be created for each order; in turn the Customer instance will then hold a collection of Orders they have made (which from this perspective I'm not interested in!!).
Could anybody help with suggestions? I've come across this issue before but I've never taken the time to design a proper solution.
Regards,
JLove
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前见过这个。诀窍是区分客户身份和客户详细信息(例如订单)。然后,您可以从所有订单对象链接到客户身份对象,并在另一个视图中从客户身份对象链接到客户详细信息对象,后者进一步链接到订单对象(您可能希望此订单按时间顺序)。
该实现可以作为对象系统或关系数据库来保存(在这种情况下,您将有一个表“客户”,其中 CustomerID 作为键,其地址等;以及一个表“订单”,其中 OrderID 作为键,CustomerID 作为另一栏。
I have seen this before. The trick is to differentiate between Customer-Identity and Customer-Details (e.g. Orders). You can then link from all Order-Objects to the Customer-Identity-Object, and in the other view link from the Customer-Identity-Object to the Customer-Details-Object which further links to Order-Objects (you probably want this ordered chronologically).
The implementation can be held as on Object-System or as a relational Database (in which case you would have a table "Customers" with CustomerID as Key, their addresses etc; and a table "Orders" with OrderID as key, and CustomerID as another column.