如何根据状态限制对类数据的访问?
在我正在开发的 ETL 应用程序中,我们有三个基本流程:
- 验证并解析来自第三方的客户信息 XML 文件 将
- 文件中收到的值与我们系统中的值相匹配
- 在我们的系统中加载客户数据
这里的问题是我们可能需要向内部用户显示上述任何或所有状态的客户信息,并且我们的客户类中有一些数据在我们的系统中匹配值之前永远不会被填充(步骤 2)。出于这个原因,我希望当客户处于这种状态时甚至无法访问这些值,并且我希望必须避免到处重复的逻辑,例如:
if (customer.IsMatched) DisplayTextOnWeb(customer.SomeMatchedValue);
我对此的第一个想法是添加几个Customer 之上的接口仅公开当前状态的属性和行为,然后仅处理这些接口。这种方法的问题在于,似乎没有好的方法可以从 ICustomerWithNoMatchedValues 转移到 ICustomerWithMatchedValues 而不进行直接转换等...(或者至少我找不到)。
我不是第一个遇到这种情况的人,您通常如何处理这个问题?
作为最后的警告,我希望这个解决方案能够与 FluentNHibernate 很好地配合:)
提前致谢......
In an ETL application I am working on, we have three basic processes:
- Validate and parse an XML file of customer information from a third party
- Match values received in the file to values in our system
- Load customer data in our system
The issue here is that we may need to display the customer information from any or all of the above states to an internal user and there is data in our customer class that will never be populated before the values have been matched in our system (step 2). For this reason, I would like to have the values not even be available to be accessed when the customer is in this state, and I would like to have to avoid some repeated logic everywhere like:
if (customer.IsMatched) DisplayTextOnWeb(customer.SomeMatchedValue);
My first thought for this was to add a couple interfaces on top of Customer that would only expose the properties and behaviors of the current state, and then only deal with those interfaces. The problem with this approach is that there seems to be no good way to move from an ICustomerWithNoMatchedValues to an ICustomerWithMatchedValues without doing direct casts, etc... (or at least I can't find one).
I can't be the first to have come across this, how do you normally approach this?
As a last caveat, I would like for this solution to play nice with FluentNHibernate :)
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太清楚,但似乎你只需要创建一个 代理类为您的班级提供数据。
I didn't understand absolutely clear but it seemed that you need just to create a Proxy-class for your class with data.
添加一个继承自 Customer 的类,名为 MatchedCustomer(例如)。然后,第 2 步就成为将客户提升为匹配客户的过程。您仍然需要编写代码来执行此操作;通常它是在构造函数中完成的:
Add a class that inherits from Customer called MatchedCustomer (e.g.). Then step #2 becomes the process of promoting a Customer to a MatchedCustomer. You still need to write the code to do this; typically it's done in the constructor: