oop - Modeling question about categorization. To subtype or not to? -


How to model this simple classification (?) Example I would like some advice:
I have a product, a product There may be different types, such as ProductType 1, ProductType 2, and ProductType 3. All products have a part number and a name. Whereas they are different, their prices are calculated accordingly.

  • Depending on how much product product is in type 1 product. So if I have 5 products, then the value is $ x if I have 20 products, then the price is IN $ Y, and so on.
  • The price of the product 2 types depend on the weight of each product. If weighs 5 kilograms, then the price is $ x, and so on.
  • Product is a simple product in 3 types, such as $ x for each product.

The way I see it, the table / class devoted to each "value structure". Depending on the type of product of a product, its value will be a reference to the structure. Can you just create a "product type" table and have properties with type attribute on the product class or will you use normalization, so the product 1/2/3 is a subtype of the product? There will be 5 different value structures, and the way the calculation of value is different from each type. Therefore logic calculating the total value for the order depends on each product type.

Can you give me some advice about how this is the best way? If I select the approach where there is a kind of property on the product class, then I think that I will get many if-else statements in my code. Where I choose to subcategory them, each class can be responsible for calculating the right price, or whatever is said to do.

I think that when using a perfect example to use if you value the product To use the class succession to decide, you will have to compile your entire system again if someone later decides that the widget XYZ should be kept at the expense of the weight rather than the simplest price.

I define each product as a "pricing strategy" - in your case it will either be "volume discounts", "by white", or "simple". You can then use it to provide the right PriceCalculator object based on the product strategy, and that calculator will calculate according to the price of the product.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -