OOP / language design question
Brian van den Broek
broek at cc.umanitoba.ca
Wed Apr 26 12:06:04 EDT 2006
Bruno Desthuilliers said unto the world upon 25/04/06 06:52 PM:
> Duncan Booth a écrit :
>
>>bruno at modulix wrote:
>>
>>
>>
>>>class Base(object):
>>> def __init__(self, arg1):
>>> self.attr1 = arg1
>>> self.dothis()
>>>
>>> def dothis(self):
>>> return self.attr1
>>>
>>>class Derived(Base):
>>> def __init__(self, arg1, arg2=0):
>>> self.attr2 = arg2
>>> Base.__init__(self, arg1)
>>>
>>> def dothis(self):
>>> return self.attr1 + self.attr2
>>>
>>>(snip)
>>>
>>>
>>>
>>>>Perhaps if the base __init__ calls an overridden
>>>>method, but at that point it sounds to me like something wants
>>>>refactoring.
>>>
>>>Why so ? This is a well-known pattern (template method). I don't see
>>>what's wrong with it.
>>
>>
>>Apart from the fact that you can delete the method 'dothis' from both
>>classes with no effect on the code?
>
>
> Mmmm... Oh, I see. Agreed, this is not a very good example.
<snip>
This hobbyist isn't seeing Duncan's point. Wouldn't deleting the
dothis method from both classes lead to an AttributeError as
Base.__init__ calls self.dothis()?
Is the point that one could refactor out the self.dothis() from the
__init__? Or something else altogether? (I assume it can't be that
dothis isn't doing real work as it is in the context of a toy example.)
Enlightenment gratefully received.
Best to all,
Brian vdB
More information about the Python-list
mailing list