callable virtual method

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Aug 14 20:29:03 CEST 2009


Nigel Rantor wrote:
> Jean-Michel Pichavant wrote:
>>
>> Your solution will work, for sure. The problem is that it will dumb 
>> down the Base class interface, multiplying the number of methods by 
>> 2. This would not be an issue in many cases, in mine there's already 
>> too much meaningful methods in my class for me to add artificial ones.
>>
>> Thanks for the tip anyway.
>
> I suggest you reconsider.
>
> You asked a question and have been given a standard way of achieving 
> the desired outcome.
>
> It's common in OO to use a Template pattern like this.
>
> If you're not interested in finding out how loads of people have 
> already solved the problem then why ask?
>
> The methods that require overriding can be prefixed with an underscore 
> so that people get a hint that they are an implementation detail 
> rather than part of the public interface.
>
> I don't see your problem, other than a vague aesthetic unease.
>
> Regards,
>
>   n
I understand how refuting some obvious solution may look just stupid. 
You're right, I shouldn't have asked.

By the way I'd like to know if I am I alone to find that

class Stream:
    def start
    def stop
    def reset

is better than

class Stream:
    def start
    def _start
    def stop
    def _stop
    def reset
    def _reset

(try to figure out with 20+ methods)
What you call aesthetic may sometimes fall into readability.


JM




More information about the Python-list mailing list