by
Dean Cooper >> Tue, 2 Mar 1999 2:08:27 GMT
I have often thought it might be nice if jade classes had the option of marking properties as transient.
This would allow you to have some properties on a class that can be modified without being in transaction state. Could be useful for partial results, caching results etc.
This is an interesting idea and one that we may consider in the future.
But you can achieve something similar today quite easily with a couple of classes and methods on app, for example:
abstract class WorkingStorage
(
referenceDefinitions:
relatedObject: Object;
)
class WorkingStorageDict subclassOf MemberKeyDictionary
(
membership:
WorkingStorage
keys:
relatedObject
)
Now you can subclass WorkingStorage with whatever classes you require, with each class containing your necessary ("transient") properties. If you need only a simple or common working storage area, then you could just make WorkingStorage a concrete class, add the additional properties you need and use it.
On your app class, add a reference (workingStores, say) of type WorkingStorageDict. You can then implement a couple of methods like the following (basic implementations):
getWorkingStorage(obj: Object; wsSubclass: Class): WorkingStorage updating; vars
ws: WorkingStorage;begin
ws := workingStores[obj];
if ws <> null then
return ws;
endif;
if wsSubclass = null then
// null working storage class
// raise an exception, return null, etc...
endif;
if not wsSubclass.inheritsFrom(WorkingStorage) then
// we create only WorkingStorage subclasses
// raise an exception, return null, etc...
endif;
if wsSubclass = WorkingStorage then
// WorkingStorage is abstract
// raise an exception, return null, etc...
endif;
create ws as wsSubclass transient;
ws.relatedObject := obj;
workingStores.add(ws);
return ws;
end;
removeWorkingStorage(obj: Object) updating;
vars
ws: WorkingStorage;begin
ws := workingStores[obj];
if ws <> null then
workingStores.remove(ws);
delete ws;
endif;
end;
Now, when you need a transient working storage area for an object (say a Customer), you can implement:
vars
cust : Customer;
wsCust : CustWorkingStorage; // subclass of WorkingStorage
begin
// some code...
wsCust := app.getWorkingStorage(cust,
CustWorkingStorage).CustWorkingStorage;
// some more code using wsCust...
epilog
app.removeWorkingStorage(cust);
end;
If you want to avoid the type guard on the call to app.getWorkingStorage you could have a method on app for each type of working storage that you need. Personal preference I guess.
Hope this helps.
Dean.