[PEAK] Persistence styles, MDA, AOP, PyProtocols, and PEAK
golux at comcast.net
Wed Jul 7 18:35:16 EDT 2004
Robert Brewer wrote:
> Stephen Waterbury wrote:
>>... in a nutshell:
>>* "OntoClass" instances, which are subclasses of dict
>>* "OntoProperty" instances that have a name, type_name,...
>>* The app domain object classes all have a '_schema' attribute
>>which is an OntoClass instance, of which the OntoProperty
>>instances are used in __init__ to create instance attributes.
>>(I'm not using metaclasses to do this yet, but might do that
>>in the future ... trying to keep this as simple as possible
>>for now. ;)
> Why separate the domain object from the OntoClass? In other words, why
> would an Invoice class "have a" schema rather than "be a" schema?
I probably didn't word that very well. What I have is:
Document._schema._OntoClass__name == 'Document'
(_schema is an OntoClass instance)
Now let's say you have a domain object 'Invoice' that
has more attributes than the generic 'Document' OntoClass,
but it doesn't need any more behaviors than Document has
(this depends on the app, of course! ;). If that's the
case, you can define a new OntoClass instance with
__name = 'Invoice', register it in the registry, and
then create invoices as Document instances that have a
_schema._OntoClass__name = 'Invoice', so they get the
additional (persistable) properties needed for invoices.
In this use case, the OntoClass acts kind of like a
If the 'Invoice' class needs new behaviors beyond what's in
my base classes, then a new Python class would need to be added
to my base classes (and to the mirroring 'base' OntoClass
instances with the same name), which then could be used
for special types of invoices that don't require more behaviors
than the generic Invoice class by adding a 'MyInvoice'
OntoClass instance to the registry, etc.
> I did basically the same thing you describe above, for the same reasons.
> You can check out the core at
> http://www.aminus.org/rbre/python/dejavu/__init__.py (and other files in
> that folder). My "OntoClass" is called "Unit", and "OntoProperty" is
> called "UnitProperty" (a descriptor). You can see how the DB tables get
> created (for ADO DB's) in
> Steal whatever you like. I don't use Twisted (yet), but I did use a tiny
> bit of metaclassing. ;)
I'll have a look -- thanks!
More information about the PEAK