创建具有相同属性的数据模型的最佳实践

Best practices creating data models with same properties

MVC 新手,正在寻找多个模型具有相同属性时的最佳实践。例如,我有几个具有地址字段(地址、城市、州和邮政编码)的模型。假设我有一个包含这些字段的客户模型和供应商模型。创建模型的最佳方法是什么?我开始的第一个例子有:

public class Customer
{
    public int Id { get; set; }
    public string AccountNumber { get; set; }
    public string Customer { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
    public string MainPhone { get; set; }
    public string fax { get; set; }
    public string ContactPhone { get; set; }
}

public class Supplier
{
    public int Id { get; set; }
    public string AccountNumber { get; set; }
    public string Supplier { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
    public string MainPhone { get; set; }
    public string fax { get; set; }
    public string ContactPhone { get; set; }
}

或者:

public class Customer
{
    public int Id { get; set; }
    public string AccountNumber { get; set; }
    public string Customer { get; set; }
    public Address CustomerAddress { get; set; }
    public Phone MainPhone { get; set; }
    public Phone fax { get; set; }
    public Phone ContactPhone { get; set; }
}

public class Supplier
{
    public int Id { get; set; }
    public string AccountNumber { get; set; }
    public string Supplier { get; set; }
    public Address SupplierAddress { get; set; }
    public Phone MainPhone { get; set; }
    public Phone fax { get; set; }
    public Phone ContactPhone { get; set; }
}

public class Address
{
    public string AddressLine1 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
}

public class Phone
{
    public int AreaCode { get; set; }
    public int NPA { get; set; }
    public int Station { get; set; }
}

非常感谢任何有关最佳实践的建议

我不知道这对于 MVC 与其他任何东西有什么不同,但是在我看来,第二种要好得多。当您决定添加工作地址和家庭住址时,就像您已经有几个 phone 号码一样,您将不必想出更多人为的名称来区分。可重用代码的所有标准原因仍然适用。