At 03:21 PM 2/12/2005, Brian van den Broek wrote: [snip] > I am curious about Bob's "Whenever you find yourself writing > an if statement ask whether this would be better handled by subclasses."
I start out writing a class like:
class A:
def __init__(self, type):
self.type = type
...
def foo(self, ...):
if self.type = 1:
statements to process object of type 1
else:
statements to process object of type 2The '"if statement" alerts me to consider creating subclasses for types 1 and 2:
class A:
...
class A1(A);
def foo(self, ...):
statements to process object of type 1
class A2(A);
def foo(self, ...):
statements to process object of type 2That takes less code. Eliminates the type property. I get greater visibility about the existence and distinction of the two (or more) sub-types. I now can much more easily extend each subtype.
Bob Gailer
mailto:[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
