首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >领域建模帮助: Product & ProductType & ProductyTypeProperties & ProductyTypePropertyValues

领域建模帮助: Product & ProductType & ProductyTypeProperties & ProductyTypePropertyValues
EN

Stack Overflow用户
提问于 2011-07-02 03:06:59
回答 1查看 129关注 0票数 1

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

在它之后,用户能够创建一个“产品”对象,并将一些ProductTypes与其关联。

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

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

我不确定如何设计这样的域对象模型。特别是如何将ProductType的属性值应用于Product对象。

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

对象结构现在看起来如下所示:

代码语言:javascript
复制
ProductType
    List<ProductTypeProperty>
        List<ProductTypePropertyValue>

Product
    List<ProductType>

我现在使用的C#类定义是:

代码语言:javascript
复制
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“和”继承“属性以及来自每个相关产品类型的可用值。

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

EN

回答 1

Stack Overflow用户

发布于 2011-08-29 22:14:04

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

一个泛型基属性类,其中TValue将确定属性值的类型(可以是字符串、小数、整数或多项选择):

代码语言:javascript
复制
    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;
        }
    }

为每种类型的属性创建一个嵌套类,例如,对于您可以创建的简单字符串属性:

代码语言:javascript
复制
public class ProductTypeStringProperty : ProductTypePropertyBase<string>
{
    public ProductTypeStringProperty(string name, string value) : base(name, value)
    {
    }
}

对于像多项选择这样的复杂属性类型,您可以实现:

代码语言:javascript
复制
public class ProductTypeMultipleChoiceProperty : ProductTypePropertyBase<MultipleChoiceValue>
{
    public ProductTypeMultipleChoiceProperty(string name, MultipleChoiceValue value) : base(name, value)
    {
    }
}

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6552249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档