Class Design Question
I am trying to figure out a good way to design my class system.
I have a class Product
to compute various product specifications. I have two product model groups, each containing several model numbers: {10, 20, 30} and {50, 60, 70}. They share some similar features (i.e. the way weight is computed) but have different product add-on computations (i.e. some features depend on product length and some do not, depending on the model group)
The class model I currently have is main Product
for all models (actually originally for 50, 60, 70 only), and a specific model Product10
was added on later and works for model 10 only. Now, a new addition brought on models 20, and 30, which are similar to model 10. Instead of adding them as separate classes, nearly identical to 10, I thought it was time to redesign.
Problem
In my current implementation, class Product10
is feeding off the main Product
class (responsible for "most models") and Product10
is being the odd one out. Maybe it is fine, but now I am getting more model numbers similar to Product10
and I am seeking a better way to structure my code.
Currently I see that there are quite a few ways to design this.
- create a class for each model (may be wasteful)
- create a "god class" that contains code for all models (class may be bloated)
- create subgroups for models, i.e. one class that covers a set of models like {10, 20, 30} or {50, 60, 70}
- something else.
What I seek
I seek a good way to use OO design for my specific situation... Namely,
- I think it is a good idea to have a generic class of some sort
- I am not sure whether I should create a class for to represent "a set of similar models" or whether to treat models separately
My goal is to create an appropriate class based on model number.
What could be a good class decomposition?