In a legacy codebase I have a very large class with far too many fields/responsibilities. Imagine this is a Pizza object.
It has highly granular fields like:
- hasPepperoni
- hasSausage
- hasBellPeppers
I know that when these three fields are true, we have a Supreme pizza. However, this class is not open for extension or change, so I can't add a PizzaType, or isSupreme(), etc. Folks throughout the codebase duplicate the same "if(a && b && c) then isSupreme)" logic all over place. This issue comes up for quite a few concepts, so I'm looking for a way to deconstruct this object into many subobjects, e.g. a pseudo-backwards Builder Pattern.
PizzaType pizzaType = PizzaUnbuilder.buildPizzaType(Pizza); //PizzaType.SUPREME
Dough dough = PizzaUnbuilder.buildDough(Pizza);
Is this the right approach? Is there a pattern for this already?
Thanks!