Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 域建模帮助:Product&ProductType&ProductyTypeProperties&ProductyTypePropertyValue_C#_Design Patterns_Data Structures_Domain Driven Design_Data Modeling - Fatal编程技术网

C# 域建模帮助:Product&ProductType&ProductyTypeProperties&ProductyTypePropertyValue

C# 域建模帮助:Product&ProductType&ProductyTypeProperties&ProductyTypePropertyValue,c#,design-patterns,data-structures,domain-driven-design,data-modeling,C#,Design Patterns,Data Structures,Domain Driven Design,Data Modeling,我有一个问题域,用户应该能够创建一个ProductType对象,其中每个ProductType对象都应该有一个聚合的ProductTypeProperties列表,每个ProductTypeProperty对象都应该有一个聚合的ProductTypePropertyValue列表 之后,用户可以创建一个产品对象并将几个产品类型与之关联 当用户将产品与几个ProductTypes关联时,用户可以为产品对象指定ProductTypeProperties的值 ProductTypeProperties

我有一个问题域,用户应该能够创建一个ProductType对象,其中每个ProductType对象都应该有一个聚合的ProductTypeProperties列表,每个ProductTypeProperty对象都应该有一个聚合的ProductTypePropertyValue列表

之后,用户可以创建一个产品对象并将几个产品类型与之关联

当用户将产品与几个ProductTypes关联时,用户可以为产品对象指定ProductTypeProperties的值

ProductTypeProperties可以具有属于不同选择模式的值,例如:一选、多选和字符串/整数/十进制输入

我不知道如何设计这样的域对象模型。特别是如何在产品对象上应用ProductType的属性值

现在我不在乎持久性,只在乎对象域模型,因为我可以自由选择SQL/Document/object/Graph数据库

对象结构现在如下所示:

ProductType
    List<ProductTypeProperty>
        List<ProductTypePropertyValue>

Product
    List<ProductType>
我现在使用的C类定义是:

public class Product {
    public string Name { get; set; }
    public List<ProductType> AssociatedProductTypes { get; set; }
    // how to apply ProductType's property values to a Product object?
}

public class ProductType {
    public string Name { get; set; }
    public List<ProductTypeProperty> AggregatedProperties { get; set; }
}

public class ProductTypeProperty {
    public string Name { get; set; }
    public List<ProductTypePropertyValue> AggregatedAvailableValues { get; set; }
}

public class ProductTypePropertyValue {
    public string Name { get; set; }
}
它看起来像是试图在对象中应用类/对象结构,其中ProductType是一个类,Product是一个对象,可以是实例ProductTypes并从每个关联的产品类型继承属性和可用值

我从来没有做过这样的对象模型,所以如何正确地做是非常有趣的。
感谢您的意见和建议。

您可以按如下方式映射ProductTypeProperty:

一个通用的基本属性类,其中TValue将确定属性值的类型,可以是string、decimal、int或多选:

    public abstract class ProductTypePropertyBase<TValue>
    {
        public string Name { get; set; }
        public TValue Value { get; set; }

        protected ProductTypePropertyBase(string name, TValue value)
        {
            Name = name;
            Value = value;
        }
    }
对于每种类型的属性,创建一个嵌套类,例如,对于简单的字符串属性,可以创建:

public class ProductTypeStringProperty : ProductTypePropertyBase<string>
{
    public ProductTypeStringProperty(string name, string value) : base(name, value)
    {
    }
}
对于复杂的属性类型(如多选),可以实现:

public class ProductTypeMultipleChoiceProperty : ProductTypePropertyBase<MultipleChoiceValue>
{
    public ProductTypeMultipleChoiceProperty(string name, MultipleChoiceValue value) : base(name, value)
    {
    }
}

其中multipleEchoiceValue是另一种表示字符串列表的类型,例如。

似乎您已经有了一个对象模型,该模型能够正确反映您正在寻找的产品的结构,包括多个产品类型、多个属性的产品类型、多个可能值的属性。如果您已经对其进行了建模,那么问题是什么?