如何根据状态限制对类数据的访问?

发布于 2024-08-27 08:44:20 字数 635 浏览 5 评论 0原文

在我正在开发的 ETL 应用程序中,我们有三个基本流程:

  1. 验证并解析来自第三方的客户信息 XML 文件 将
  2. 文件中收到的值与我们系统中的值相匹配
  3. 在我们的系统中加载客户数据

这里的问题是我们可能需要向内部用户显示上述任何或所有状态的客户信息,并且我们的客户类中有一些数据在我们的系统中匹配值之前永远不会被填充(步骤 2)。出于这个原因,我希望当客户处于这种状态时甚至无法访问这些值,并且我希望必须避免到处重复的逻辑,例如:

if (customer.IsMatched) DisplayTextOnWeb(customer.SomeMatchedValue);

我对此的第一个想法是添加几个Customer 之上的接口仅公开当前状态的属性和行为,然后仅处理这些接口。这种方法的问题在于,似乎没有好的方法可以从 ICustomerWithNoMatchedValues 转移到 ICustomerWithMatchedValues 而不进行直接转换等...(或者至少我找不到)。

我不是第一个遇到这种情况的人,您通常如何处理这个问题?

作为最后的警告,我希望这个解决方案能够与 FluentNHibernate 很好地配合:)

提前致谢......

In an ETL application I am working on, we have three basic processes:

  1. Validate and parse an XML file of customer information from a third party
  2. Match values received in the file to values in our system
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

是你 2024-09-03 08:44:21

我不太清楚,但似乎你只需要创建一个 代理类为您的班级提供数据。

I didn't understand absolutely clear but it seemed that you need just to create a Proxy-class for your class with data.

可爱暴击 2024-09-03 08:44:20

添加一个继承自 Customer 的类,名为 MatchedCustomer(例如)。然后,第 2 步就成为将客户提升为匹配客户的过程。您仍然需要编写代码来执行此操作;通常它是在构造函数中完成的:

public class MatchedCustomer : Customer
{
    public MatchedCustomer(Customer customer)
    {
        // set properties from customer, i.e.
        FirstName = customer.FirstName;
    }
}

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:

public class MatchedCustomer : Customer
{
    public MatchedCustomer(Customer customer)
    {
        // set properties from customer, i.e.
        FirstName = customer.FirstName;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文