Translating some Java to Python

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 21 07:29:08 EDT 2007


En Mon, 21 May 2007 07:39:09 -0300, Unknown <unknown at unknown.invalid>  
escribió:

> "Ant" <antroy at gmail.com> schreef in bericht
> news:1179738814.282655.192700 at r3g2000prh.googlegroups.com...
>
>> Herman has shown you *how* to do static methods in Python, but
>> typically they are not used. Since Python has first class functions,
>> and they can be defined at the module level, there is no need to use
>> static methods.
>
> As an experienced developer I'm rather new to Python, so please forgive  
> me any non-Pythonic babbling.
>> From a language point you're probably right, but from a design point I'd
> like to have methods that are clearly associated with a class as methods  
> of that class, even if they don't use any class or instance related data.

In that case you might want to revise the design, perhaps you carry some  
preconceptions about how things should be, that are not directly  
applicable here. (I'm not saying this is related to your specific problem  
because I don't know exactly what you want, but in general, a lot of  
design patterns *implementations* are not directly applicable to Python).
Modules are objects too - they're a good example of singletons. If you  
want to create a class containing only static methods: use a module  
instead. If you want to create a class having a single instance (a  
singleton), most of the time you can use a module instead.
Functions don't *have* to be methods in a class, and the resulting design  
may still be a good design from an OO point of view.

-- 
Gabriel Genellina




More information about the Python-list mailing list