to subclass or not to subclass...
-
...that is the question.
My app controls a medium-sized (~100) pieces of equipment. Each equipment item can be classified into (exactly) one category; there are ~40 categories in an installation.
I have a list model to maintain a list of equipment. This model is exposed to QML using the convention means.
I'm considering the options for how to process each category of equipment. One option is to have a "super-category" which contains all of the properties of all the categories. This would be simple to implement, but has the drawback of creating a large class, whose data() and setData() functions will have to check for every property, possibly affecting performance. It will also be a relatively complicated class.
The other option is to subclass each category. There are two drawbacks that I see to this approach:
-
this will entail a lot of coding, possibly with a fair amount of redundancy.
-
I'll have to implement the equipment item list as a list of pointers, with the associated risk of memory leaks.
Neither of these options thrill me. I'd welcome opinions on which is the lesser of two evils, as well as any ideas for another way to do this.
Thanks...
-
-
@JoeCFD said in to subclass or not to subclass...:
Is it possible to group categories with similar properties?
This occurred to me, so I asked about it. It seems that trying to group the categories would result in ~30 groups, so it's not much help.I'm leaning towards the first option. It's going to create a huge class, and the data()/setData() functions are going to be quite large and/or complicated, which could be a mild performance issue, but overall it seems better (simpler) than subclassing and having to deal with each subclass in the model. Like I said, I'm not thrilled with either option.
-
@SGaist interesting suggestion, but probably not viable for this application.
What I need is a way to break up the processing routine by category, which relies on multiple local variables. I guess I could create a function in the specialized class, and pass it all those local variables, but...that makes it seem like I need a subclass.
I also considered a friend function within my model class, but I can't give it context without creating a lot of circular references.
Aargh...I may not have a solution, but I'm certainly admiring the problem.
-