帮助在 asp.net 中定义域模型

发布于 2024-12-03 05:09:49 字数 237 浏览 1 评论 0原文

我需要帮助模拟这个场景。

一个病人可以有很多医生,

一个医生可以有很多病人。

患者也是用户。 (MembershipUser)

医生也是用户。 (MembershipUser)

它们有很大不同,因为(例如)患者会进行多次体检,而医生则不会。

这应该是课程吗?将这样的类绑定到特定 MembershipUser 的标准方法是什么?

我很难理解这一点。

I need help modeling this scenario.

A Patient can have many medics

A Medic can have many patients.

A Patient is also a User. (MembershipUser)

A Medic is also a User. (MembershipUser)

They are quite different because (for example) a Patient will have many PhysicalExams whereas a Medic wouldn't.

Should this be classes? what is the standard approach of tying a class like this to a specific MembershipUser?

I have trouble understanding this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

爱*していゐ 2024-12-10 05:09:49

您可以在域层使用类似的内容:

public class Credentials {
    private String _userName;
    private String _email;
    private String _passwordQuestion;
}

public abstract class User {
    private Credentials _credentials;
}

public class Patient : User {
    private List<Medic> _medics;
    private List<PhysicalExam> _exams;
}

public class Medic : User {
    private List<Patient> _patients;
}

请注意,域代码不直接引用 ASP.NET 成员身份。您的基础结构可以负责将域 User 对象映射到 ASP.NET MembershipUser:

public class AspNetMembershipProvider {
    public MembershipUser BasedOn(User user) {
        return new MembershipUser(user.UserName, user.Email, ...)
    }    
}

You can have something like this at the domain layer:

public class Credentials {
    private String _userName;
    private String _email;
    private String _passwordQuestion;
}

public abstract class User {
    private Credentials _credentials;
}

public class Patient : User {
    private List<Medic> _medics;
    private List<PhysicalExam> _exams;
}

public class Medic : User {
    private List<Patient> _patients;
}

Note that domain code does not reference ASP.NET Membership directly. Your infrastructure can be responsible for mapping domain User object to ASP.NET MembershipUser:

public class AspNetMembershipProvider {
    public MembershipUser BasedOn(User user) {
        return new MembershipUser(user.UserName, user.Email, ...)
    }    
}
街道布景 2024-12-10 05:09:49

根据您的解释,我只会有一个可能称为 User 的抽象基类,它定义患者和医生共享的重复属性和方法。

然后,我将在该基类中公开一个公共属性,即 MembershipUser 对象。

然后只需让 Patient 和 Medic 类继承 User 基类并实现各自独特的功能即可。

基本用户类还可以实现一个公共属性,该属性是 T 的列表,该列表具有将 T 限制为 User 对象的 where 子句,

如下所示:

public abstract class User<T> where T : User<T>
{
    public MembershipUser Membership { get; set; }
    public List<T> Users { get; set; }

}

public class Patient : User<Medic>
{

}

public class Medic : User<Patient>
{

}

From your explanation I would simply have a an abstract base class maybe called User which defines the duplicate properties and methods that both Patient and Medic share.

I would then have a public property exposed in that base class that is the MembershipUser object.

Then just make Patient and Medic classes inherit from the base User class and implement their respective unique functionality.

The base user class could also implement a public property that is a List of T that has a where clause that restricts T to User objects

Something like this:

public abstract class User<T> where T : User<T>
{
    public MembershipUser Membership { get; set; }
    public List<T> Users { get; set; }

}

public class Patient : User<Medic>
{

}

public class Medic : User<Patient>
{

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文