我正在尝试使用DDD指南设计电子商务系统的领域模型。我有一个情况,其中有2种不同类型的产品。一种产品是“项目”,另一种产品是“包”(项目的组合/捆绑)。到目前为止,我的领域模型如下:
public abstract class Product : IAggregateRoot
{
public string ProductId { get; protected set; }
// Many to Many relationship between Item and Package
protected List<ItemPackageRelationship> ItemPackages => new List<ItemPackageRelationship>();
protected List<Image> Images => new List<Image>();
// Other properties shared between Item and Package
}
public class Item : Product
{
// All properties and methods specific to Item
public void SetImages(List<string> images)
{
// Set images for Item has its own business logic
// Example: number of allowed images, size of image etc
}
}
public class Package : Product
{
// All properties and method related to package
public void SetImages(List<string> images)
{
// Set images for Package has its own business logic
// Exampe: number of allowed images, size of image etc
}
}
所有的行为都定义在Item和Package类中,而Product类只有共享属性。最初我考虑创建两个完全独立的聚合根(Item和Package),而没有Product实体。我需要Product仅仅是因为系统中唯一的ProductId。而所有与其他实体(如Images)的关系都需要基于ProductId。
我并不100%确定我设计的是否正确,需要一些意见。仅仅为了共享一些属性而创建基础实体是否违反了DDD的原则?还有其他什么建议可以改进我的领域模型设计吗?
非常感谢您提前的帮助。