I have been given a task that can be simplified to this scenario:
Customers need to order boxes and these boxes can come in different sizes, the different sizes can be ordered in certain colours (but not all colours) and have different qualities (but not all qualities).
Now I believe the best way to approach this would be to make the box class the abstract class and have the different boxes extend the box class to prevent repetitive code, but then the issue comes in, how do I check an order a client puts in is valid without storing static variables in the class (this class cannot have this colour etc.)?
My solution is to simply put static variables in each extension of the class and then check each class without initialising a new object but it means having repeating variable declarations in each class.
Any help is appreciated.
Unless you you’re willing to have a really complicated class hierarchy, you might want to consider using a look-up table instead of inheritance/polymorphism. It will definitely be easier to follow and maintain.
The accessors to your look-up table might be something like
etc.
Update
The only sane way you can use OOP principles here is if you have enough information about the relationships to define a hierarchy.
For instance:
If you’ve got more info about the assignemnt, post it.