[PEAK] Persistence styles, MDA, AOP, PyProtocols, and PEAK

Stephen Waterbury golux at comcast.net
Thu Jul 8 02:08:59 EDT 2004

Robert Brewer wrote:
> Stephen Waterbury wrote:

>>Cool -- just a slightly different approach from mine.
>>Here's how it would look in PanGalactic.
> Gargleblasters anyone? ;)

Bingo!  (I even got http://pangalactic.us ... :)

> Looks good! You might want to check into coding your own descriptors
> instead of using properties--it really cuts down on the boilerplate
> (obviously the above is just an example, but still...).

Right, that stuff was just for your example.

The way the _schema's OntoProperties get added to
PanGalactic objects doesn't use Python properties ...
it's much simpler.  Here's the code from the base
PGEF (Pan Galactic Engineering Framework) class,

    def __init__(self, **kw):
        Initialize a PgefObject.
        # if a _schema is supplied as kw arg, use it;
        # if not, use the class's _schema ...
        if kw.get('_schema', None):
            self._schema = kw['_schema']
        for a in self._schema:
            if a in kw:
                setattr(self, a, kw[a])
                # default values are defined in the OntoProperties
                # (recall that OntoClass subclasses dict, and
                # maps OntoProperty names to OntoProperty objects,
                # so self.schema[a] is the OntoProperty whose name
                # is the value of a.
                setattr(self, a, self._schema[a].default)

... as I say, very simple!  No boilerplate needed.
I may get fancy later and use metaclasses to make them
into real properties, but for now that's YAGNI.  ;)


More information about the PEAK mailing list