[Python-3000] Generic functions vs. OO
Phillip J. Eby
pje at telecommunity.com
Mon Nov 27 21:25:14 CET 2006
At 02:34 PM 11/27/2006 -0500, Jim Jewett wrote:
>I'm not sure that adding it to the builtin (but in a new name) would
>really buy much over an adapter (x in MyProto("asdf") ), but the
>interface fans may feel differently.
For what it's worth, in Chandler there is a system called Annotations that
allows third-party packages to add private attributes to existing
(persistent) data types. It's used to implement "stamping", which is a way
that you can (for example) dynamically change a note or photo into a task
or a calendar event.
So, if I want to be able to add calendar information to "stampable"
objects, I can do something like:
# field definitions here
# method definitions
And then I can access fields on stamped items by using e.g.
CalendarEvent(someItem).startTime. So, effectively CalendarEvent is a kind
of adapter class, but we don't use the word adapter, simply because it
isn't relevant to the application domain. It's simply a way of having an
open system for adding additional data to existing object types. There are
no interfaces or generic functions involved, either, it's just a way of
separating namespaces belonging to independent developers.
I just mention it because the reaction to it among developers with no
previous exposure to Python adaptation has been fairly positive.
More information about the Python-3000