object.enable() anti-pattern

Fábio Santos fabiosantosart at gmail.com
Mon May 13 02:32:36 EDT 2013


On 13 May 2013 00:22, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
>
> Wayne Werner wrote:
>>
>> On Fri, 10 May 2013, Gregory Ewing wrote:
>>
>>>   f = open("myfile.dat")
>>>   f.close()
>>>   data = f.read()
>>
>>
>> To clarify - you don't want a class that has functions that need to be
called in a certain order with *valid input* in order to not crash.
>>
>> Exactly what does happen - a ValueError is raised because you're(*)
passing self into the file.read() function, and that input is invalid
>
>
> The same argument can be applied to:
>
>    foo = Foo()
>    foo.do_something()
>    foo.enable() # should have done this first
>
> You're passing an invalid input to Foo.do_something,
> namely a Foo that hasn't been enabled yet.
>
>
> --
> Greg
> --
> http://mail.python.org/mailman/listinfo/python-list

I don't think you can really count that as invalid input in OOP terms.
After all in most languages `self` / `this` / whatever is not an argument
to every method.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130513/01e063b3/attachment.html>


More information about the Python-list mailing list