I'm trying to design a base class for a hierarchy. The properties I want to specify for the base class depend on the values of other properties of the base class. For instance, in this toy example of a base FoodProcessor class:<div>
<br><div>class FoodProcessor:</div><div> "Model for a kitchen appliance food processor"</div><div> speed_settings # example [1, 2, 3, 4]</div><div> blade_settings # example ["slice", "grate", "grind"]</div>
<div> slice_thickness # example ["thin", "thick"], but only if blade_setting is "slice"</div><div><br></div><div>it only make sense to have the slice_thickness property set when blade_settings = "slice"; otherwise, it would be preferable to only define the speed_settings and blade_settings properties. For example:</div>
<div><br></div><div>class ProcessorA(FoodProcessor):</div><div> "A slicing-only processor"</div><div> speed_settings = [1, 2, 3, 4]</div><div> blade_settings = "slice"</div><div> slice_thickness = ["thin", "thick"]</div>
<div><br></div><div>class ProcessorB(FoodProcessor):</div><div> "A non-slicing processor"</div><div> speed_settings = [1,2,3,4] </div><div> blade_settings = ["grate", "grind"]</div>
<div> slice_thickness = None</div><div><br></div><div>Can anyone suggest some work-arounds, or refactoring for this type of design? Is there a design pattern for this?</div><div><br></div><div>Thanks!</div><div>Marcus</div>
<div><br></div><div><br></div><div><br></div></div>