pre-PEP generic objects

Carlos Ribeiro carribeiro at gmail.com
Fri Dec 3 09:22:46 EST 2004


On Fri, 03 Dec 2004 08:58:48 -0500, Istvan Albert
<ialbert at mailblocks.com> wrote:
> On the other hand, it would be nice to have a module that
> implements various design patterns. The Bunch, the Borg, the Null,
> the Proxy all nicely documented tucked away in their separate
> module. That would feel a lot less like littering the standard name space
> with an class that just "seems"  to be useful.

Great idea. I have explored some ideas relating generic objects with
"standard" patterns, namely "observer" & "proxy".

One of the applications of generic objects is to allow for data
sharing between objects of different classes that happen to share a
few attributes; sometimes it's not possible to pass the entire object
around for the other one to copy the data, either because of safety
reasons, or because there is some slightly mismatch between the
interfaces. The generic, in this case, can be implemented either as an
intermediate storage structure (as a data-only records) or as an
"proxy" that exposes only the desired attributes. In this case, data
is passed around and copied manually, using the generic (or the
"proxy" object).
 
Another use case is when one wants to implement the "observer" pattern
(which would allow for a "live" data sharing).   One alternative is to
use a "generic" as the base "observable'  object; other objects can
register with the generic and simply receive notifications, or even
share the references to its internal attributes (btw, Python
descriptors & properties are incredibly useful in this case).
Extending it even further -- the observed object could accept
modifications from its observers, although in this case we're already
talking a about more complex pattern than the standard "observer"
(btw, how is it called?).

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list