parent-child object design question

manstey manstey at csu.edu.au
Fri Feb 2 16:53:21 EST 2007


Hi,

There was a mistake above, and then I'll explain what we're doing:
>>> insCacheClass = CacheClass(oref)
>>> insCacheProperty = CacheProperty(insOref,'Chapter')

should have been
>>> insCacheClass = CacheClass(oref)
>>> insCacheProperty = CacheProperty(insCacheClass ,'Chapter')

Now, to answer some questions.
1. Cache refers to Intersystems Cache database, an powerful oo dbase
that holds our data.
2. It comes with a pythonbinding, but unfortunatley the API, written
in C as a python extension, only provides old-style classes, which is
why we wrap the oref (an in-memory instance of a Cache class/table)
with CacheClass. This allows us to add attributes and methods to the
CacheClass, the most important being CacheProperty, which is a class
corresponding to the Cache property/field classes of the dbase.
3. The pythonbind also has a strange behaviour, to our view. It gets
and sets values of its properties (which are classes), via the
'parent' oref, i.e. oref.set('Name','Peter'). But we want a pythonic
way to interact with Cache, such as, insCacheClass.Name='Peter'. and
insOref.Name.Set(). The code above (in post 7) does this, but as I
asked, by storing the parent instance (insCacheClass) inside each of
its attributes (insCacheProperty1,2, etc).
4. Another reason we want a new-style class wrapped around the oref,
is that each oref has many methods on the server-side Cache database,
but they are all called the same way, namely,
oref.run_obj_method('%METHODNAME',[lisArgs]). We want to call these in
python in the much better insCacheClass.METHODNAME(Args). E.g. we
prefer insCacheClass.Save() to oref.run_obj_method('%Save',[None]).
More importantly, the in-memory version of Cache lists and arrays are
Cache lists and arrays, but these are not Python lists and
dictionaries, but they can be easily converted into them. So having a
class for each dbase property allows us to have Cache on disk
(server), get the Cache list/array to python in memory, but still in
Cache dataformat (e.g. %ListOfDataTypes) and convert it to a python
list. Tweaking the set and get methods then lets us use python lists
and dics without ever worrying about cache dataformat.

I hope this clarifies what we are doing. We are not experienced
programmers, but we want to do it this way.




More information about the Python-list mailing list