I have written a program according to a specification.
The Specification has about 3 types and each type gets handled differently on every single point.
That means more or less for code readability, I have written it like shown below, now my question is, if you have 200 such statements, wouldn’t it be worth to merge them all into one “if enum-type x”
I would believe there is a program out there which already does it but google didn’t help me much for this specific problem. Thanks for help in advance.
/* Point 1.15 Filling Customers bdate */
if(current.identifier == APPLE){ output.setValue(1.15, additionalObj.some.color)}
if(current.identifier == PLUM){ output.setValue(1.15, otherObj.another.color) }
if(current.identifier == GRAPE){ output.setValue(1.15, default::color) }
/* Point 1.16 Filling Customers cash*/
if(current.identifier == APPLE){ do whatever}
if(current.identifier == PLUM){ do whatever}
if(current.identifier == GRAPE){ do whatever}
Result to be achieved:
if(current.identifier == APPLE){ output.setValue(1.15, additionalObj.some.color)
do whatever
}
And so on so i can merge them into 1 statement automatically while i still have the readable code
Edit: I might have misinformed you, its actually not a type its just an Object with a String identifier and SubObjects so i can’t use polymorphism. I have adjusted the above so you can see what i would like to achieve.
Basic polymorphic approach:
More likely, you’d move most of the main flow into the base class.