"Gabriel Genellina" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] > En Mon, 21 May 2007 07:39:09 -0300, Unknown <[EMAIL PROTECTED]> > escribió: > >> "Ant" <[EMAIL PROTECTED]> schreef in bericht >> news:[EMAIL PROTECTED] >> >>> 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).
I don't really have problems with Python (yet), merely responding to the OPs question. One example that comes to mind is a class that is a proxy for a database class, say Person. The Person.Load(id) method doesn't use any instance or class data, it instantiates a Person and populates it from the database. It is clearly a part of the class's interface so for that I use a @staticmethod. > 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. *That* Pythonic I'm already ;-) For a utility 'class' I'm using a module, no need for a class there. Using a module for a Singleton is good tip though. Herman -- http://mail.python.org/mailman/listinfo/python-list