OO conventions
Daniel Nogradi
nogradi at gmail.com
Wed Feb 1 17:40:37 EST 2006
I'm relatively new to object oriented programming, so get confused
about its usage once in a while. Suppose there is a class Image that
has a number of methods, rotate, open, verify, read, close, etc. Then
to use this class my natural guess would be to have something like
image = Image( )
image.read( "myfile.jpg" )
image.rotate( )
image.close( )
But now it turns out that the PIL module uses this as
image = Image.open( "myfile.jpg" )
image.verify( )
image.rotate( )
image.close( )
Perhaps the real Image class of PIL doesn't have these methods
exactly, but doesn't matter, my point is the way it works. Is it
normal that instead of first creating an instance of a class, it
starts right away with one its methods? I of course understand that
the PIL people simply made a choice that their module works this way,
period, but I'm just wondering if it wouldn't have been more "logical"
to do it along the way of my first example.
I guess it's just a matter of convention or how the programmer feels
like, but there are no conventions of this type? Which would be more
pythonic? Or I shouldn't worry and it's totally up to the developer?
More information about the Python-list
mailing list