First of all, you should consider each sku as an attribute of one product, and not combine them. If the product can have color and size, these are two different attributes, and not one (as in red / small, red / medium, etc.). Suppose a product has five attributes, each of which has 4 possible meanings. Then you will have 4^5=1024 skus. This is quickly becoming a nightmare for maintenance.
So, the first two objects in your domain model should be ProductDefinition and Attribute . The reason I choose ProductDefinition as a name rather than Product is because it is just a label for some type of product, such as a shirt. This is not a small yellow shirt.
Attributes can have possible values, so this is the third domain object: AttributeValue . The ratio between Attribute and AttributeValue is 1: n. An attribute has several values; a value belongs to only one attribute.
Note that AttributeValue contains all possible values ββfor the attribute, not the actual value for a single product. This actual value becomes the relationship between ProductDefinition , Attribute and AttributeValue : ProductAttributeValue . For an example of a shirt in a database model:
ProductDefinition Attribute AttributeValue 1 | Shirt 1 | Color 1 | 1 | Red 2 | Size 2 | 1 | Yellow 3 | 1 | Green 4 | 2 | Small 5 | 2 | Medium 6 | 2 | Large
Now we have modeled one product definition, two attributes and three attribute values ββfor each attribute. Suppose now we want to simulate three shirts: small red, small green and large yellow. This results in the following contents of ProductAttributeValue ( ProductId , ProductDefinitionId , AttributeId , AttributeValueId ):
ProductAttributeValue 1 | 1 | 1 | 1 1 | 1 | 2 | 4 2 | 1 | 1 | 3 2 | 1 | 2 | 4 3 | 1 | 1 | 2 3 | 1 | 2 | 2
source share