Jean-Michel Pichavant a écrit :
(snip)
Sometimes the base is doing cool stuff but incomplete stuff which
requires knowledge only hold by the sub class. In my case the interface
is a high level interface for a software that can run on multiple
hardware platforms. Only the sub class has knowledge on how to operate
the hardware, but no matter the hardware it still produces the same effect.
Let's say I have 50 different hardwares, I'll have 50 sub classes of
Interface with the 'start' method to define. It wouldn't be appropriate
(OO programming)to write 50 times '_log.debug('Starting %s' % self)' in
each child start method when the simple task of logging the call can be
nicely handled by the base class.
Which is exactly one of the use cases for the Template Method pattern in
traditional OO design.
For the record, Python can offer other solutions to this kind of problem
- like a combination of decorators and metaclasses.
In the meantime, I must make sure the user, who is not a python guru in
this case, has implemented the start method for his hardware,
whether he has to implement the 'start' or '_start' method doesn't make
any difference here.
--
http://mail.python.org/mailman/listinfo/python-list