16 August 2010

Python descriptor class

What is python descriptor exactly? Check this out:

http://tinyurl.com/6kj9k8




To elaborate more, a descriptor is any NEW-style python object whose class supplies special methods of a combination of the following three: __get__, __set__, __delete__. Old-style python object supports descriptors with only __get__ method.


Python recognizes descriptor class itself and calls corresponding methods based on the behavior of access. The advantage of using descriptor class is to create descriptor design pattern, which is heavily used by database. With the help of descriptors, an object instance could provide access control over its attributes! For detailed explanation and examples, refer to the link above.


What does descriptors have to do with python properties?!


The property function gives us a handy way to implement a simple descriptor without defining a separate class! In other words, python property function is just a built-in overriding descriptor type, which you may use to give a class's instances properties! This is property design pattern!


Check the following link for python properties: http://tinyurl.com/243f4td

No comments: