I am wondering if there is a design pattern for such problem:
Let's say we are building a web shop for a doors and windows manufacturer, where customer has a catalog (list) of products, from which he can choose some and customize them, before placing an order.
Each product has it's properties defined, like name, price, description. Obviously, the customer is not allowed to change any of these properties. But there is a space to customize the product. When he chooses a window, then he can choose it's colour, dimensions, perhaps a color of glass and choose some additional features. When he chooses doors, then he can choose a color, dimension, but also a type of the lock.
First idea that came to my mind is:
- Create products definitions classes (WindowDefintion, DoorsDefinition), which hold information about the name, price, description. These are listed in a catalog
- Create product instances classes (Window, Doors), which hold reference to the product, but also add customizable fields, which are specific to certain instance.
Disadvantages are perhaps silly, because it is mostly about creating a definition class for each instance class, but this involves more doubled amount of database tables and repositiories as well. I was just wondering if there is some other solution?
This example is not the case. I am using it to ease understanding of the problem. In the case, products don't have a good common generalization, which a Product would give in this case (good for having name, description and price properties).