I'd be interested to see a working example of
breaking description dependencies to avoid runaway processes.
That depends on where the recursion happens. Imagine the following
problem:
Person class>>descriptionPartner
^ MAToOneRelationDescription new
reference: self description;
yourself
This is purely Smalltalk and Magritte cannot do anything about the
recursion caused here. When you evaluate "Person description"
Magritte will collect all the description elements and also call
#descriptionPartner that calls #description and leads to an infinite
recursion.
1. The simplest solution to this problem is a hack:
Person class>>descriptionPartner
^ (MAToOneRelationDescription selector: #partner)
reference: (MADynamicObject on: [ self description ]);
yourself
MADynamicObject is a proxy that delegates most of its messages to the
result of the block evaluation. This is easy and mostly works,
however it is very hard to debug and usually leads to problems sooner
or later. There are a couple of examples in Magritte, Pier and Pier-
Unix-Security of this hack. This does not solve the problem with the
recursion when validating or printing the object.
2. Another solution is just to exclude the circular references from
the referenced:
Person class>>descriptionPartner
^ (MAToOneRelationDescription selector: #partner)
reference: (MADynamicObject on: [ self
descriptionWithoutReferences ]);
yourself
And then you need to implement something like this:
Object class>>descriptionWithoutReferences
^ self description reject: [ :each | each isKindOf:
MAReferenceDescription ]
Not very nice, but it works well. It should also solve the problem
when validating or printing a recursive object.
3. Compose your descriptions dynamically on the instance side.
Person>>description
| desc part |
desc := MAContainer new.
part := MAToOneRelationDescription selector: #partner.
desc add: (part copy reference: part).
^ desc
Ugly and looks like a Java UI built manually, but it also works for
validating or printing recursive objects.
As I mentioned in earlier mails the goal would be to enable the
detection of recursion in validation, printing and serialization
automatically.
Note: Magritte seems to lack some feature in the field of complex
composed objects (especially if you compare it with EMOF that has
something like an 'opposite' for back references, etc). This comes
from the fact that most (or even all) my described objects form a
tree and not a graph with loops. Of course the object model has
loops, but they are all handled manually with the glue-code in-
between that is not considered by Magritte. That's the power of
Smalltalk, everything is real close together ...
HTH,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch