NEWBIE: What's the instance name?

Gabriel Genellina gagenellina at softlab.com.ar
Mon Dec 29 23:44:59 CET 2003


At 29/12/2003 11:03, you wrote:

>Some of the classes have a common (or near common) display routine,
>others are totally different. If I use lx.display(), the display code
>has to be contained as a method in each class. I chose, for ease of
>maintenance, to make a display module with all the display routines
>gathered together in one spot. . In the event a future programmer
>decided to make a change to the display routine for a given class, or
>needed to add a class/display, I feel there's less chance of his/her
>messing up the UPCA-like classes. I guess I'm a believer in
>classes/methods doing a limited number of things, and doing them well.
>Is that a C hang-over?

You could define anyway a display() method in each class, and delegate the 
implementation to another module:

class UPCE(UPCA):
     def display(self):
         othermodule.display_nice_upce_instances_as_I_know_how_to_do_that(self)

class UPCF(UPCA):
     def display(self):
         othermodule.call_another_display_function(self)


Gabriel Genellina
Softlab SRL






More information about the Python-list mailing list