我有 7 节课:
public class Entity
{
public int Id { get; set; }
}
public class Product : ????
{
// Contructor
public Product()
{
Photos = new HashSet<PhotoSource>();
ProductFeatures = new HashSet<ProductFeature>();
}
// Primitives
public string ProductName { get; set; }
public string InternalSKU { get; set; }
public string ModelNumber { get; set; }
public string Description { get; set; }
public int QtyPerUnit { get; set; }
public double UnitPrice { get; set; }
public int UnitsInStock { get; set; }
public int UnitsOnOrder { get; set; }
public int? ReOrderLevel { get; set; }
public string Warranty { get; set; }
// Foreign Keys
public int SubCategoryID { get; set; }
public int VendorId { get; set; }
// Navigation Properties
// Classes
[ForeignKey("SubCategoryID")]
public virtual SubCategory SubCategory { get; set; }
[ForeignKey("VendorId")]
public virtual Vendor Vendor { get; set; }
// Collections
public virtual ICollection<PhotoSource> Photos { get; set; }
public virtual ICollection<ProductFeature> ProductFeatures { get; set; }
}
public class ProductSeasonal : ????
{
// Primitives
public int? OffSeasonDiscount { get; set; }
public DateTime SeasonStartDate { get; set; }
public DateTime SeasonEndDate { get; set; }
public int? QtyLimitedTo { get; set; }
}
public class ProductDiscontinued : ????
{
// Primitives
public DateTime DiscontinuedDate { get; set; }
public int DiscontinuedDisount { get; set; }
}
public class Supply : ????
{
// Primitives
public String UnitMeasurement { get; set; }
}
public class Part : ????
{
// Primitives
public String UnitMeasurement { get; set; }
}
public class Vehicle : ????
{
// Constructor
public Vehicle()
{
ExteriorFeatures = new HashSet<ProductFeature>();
InteriorFeatures = new HashSet<ProductFeature>();
SafetyFeatures = new HashSet<ProductFeature>();
}
// Primitives
public string VIN { get; set; }
public int Year { get; set; }
public int CylinderSize { get; set; }
public double EngineSize { get; set; }
public string StyleType { get; set; } //Truck, SUV, Sedan, Convertible, etc
public string TransmissionType { get; set; }
public string InteriorColor { get; set; }
public string ExteriorColor { get; set; }
// Foreign Keys
public virtual int MakeId { get; set; }
// Navigation Properties
// Classes
[ForeignKey("MakeId")]
public virtual VehicleMake Make { get; set; }
// Collections
public virtual ICollection<ProductFeature> InteriorFeatures { get; set; }
public virtual ICollection<ProductFeature> ExteriorFeatures { get; set; }
public virtual ICollection<ProductFeature> SafetyFeatures { get; set; }
}
设置车辆、零件、用品和任何 future 销售项目类别的继承的最佳方式是什么[例如。服装] 可以通过编码多余的属性而不必大惊小怪地添加吗?
最佳答案
最好的开始方法是写下当前感兴趣的每个项目的所有属性。
因此,任何产品都会有价格和一些唯一的 ID(sku 编号),可能还有条形码和图像。
所以,这些可能是某些父类的开始。
当您浏览其他产品时,您可能会发现共性。
如果您需要开始销售牛仔裤,请看看可能还需要哪些其他服装,因为您可能希望列出 Material 或款式。
但是,不要尝试设计您的类,以便它们能够处理任何事情。
针对您现在拥有的内容进行设计,但要使其足够灵活,以便您可以根据需要添加新属性。例如,现在我不会添加二维码图像,但以后可能会很常见,可以添加。
您的问题实际上是针对类设计还是最终针对数据库设计?
关于c# - 设置继承以避免 future 代码冗余的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443473/