[Tutor] dictionary dispatch for object instance attributes question

Brian van den Broek bvande at po-box.mcgill.ca
Wed Feb 16 20:49:16 CET 2005

Brian van den Broek said unto the world upon 2005-02-16 14:04:
> Kent Johnson said unto the world upon 2005-02-16 05:58:
>>> if 'text' == self.document_type:
>>>    self.do_text_stuff()
>>> if 'RTF' == self.document_type:
>>>    self.do_RTF_stuff()
>> Conditionals on a 'type' flag are a code smell that suggests using 
>> subclasses. Maybe you should have a TextNode class and an RtfNode 
>> class. Then the above becomes just
>>   self.do_stuff()
>> and TextNode and RtfNode each have the appropriate implementations of 
>> do_stuff().
>> I'm not saying this is the right choice for you, just something you 
>> might consider.
>> Kent
> Hi Kent,
> thanks for the snipped discussion on handlers -- very useful.


> I had been thinking better to get everything working and then refactor. 
> Is that an unsound approach? My worry about refactoring now is that I 
> feel like I am rearranging deck-chairs when I should be worried about 
> getting the ship to float :-)
> Thanks and best to all,
> Brian vdB

Hi all,

as applied to my particular case -- strike the above. I just spent 
some time looking at my code and playing in the interpreter and have 
come to the conclusion that, in this case at least, the refactor Kent 
suggested isn't playing with deck chairs. It's more like installing 

Thanks and best,

Brian vdB

More information about the Tutor mailing list