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:
class FoodProcessor:
"Model for a kitchen appliance food processor"
speed_settings # example [1, 2, 3, 4]
blade_settings # example ["slice", "grate", "grind"]
slice_thickness # example ["thin", "thick"], but only if
blade_setting is "slice"
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:
class ProcessorA(FoodProcessor):
"A slicing-only processor"
speed_settings = [1, 2, 3, 4]
blade_settings = "slice"
slice_thickness = ["thin", "thick"]
class ProcessorB(FoodProcessor):
"A non-slicing processor"
speed_settings = [1,2,3,4]
blade_settings = ["grate", "grind"]
slice_thickness = None
Can anyone suggest some work-arounds, or refactoring for this type of
design? Is there a design pattern for this?
Thanks!
Marcus
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor