开发者

Help defining a Domain Model in asp.net

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 ex开发者_开发问答ample) 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.


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, ...)
    }    
}


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>
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜