Essentially, I would like to keep track of all objects that have references to a certain object in the current system state. This information could be used to infer the relationships between runtime objects, e.g,, whether the relationships are temporary or more "permanent". The two patterns I described reflect this idea. That is, an new object is created, but the creating object does not hold any reference to it, either through a local variable or a field. And the only purpose for creating this object is to pass it to others (
e.g., in factory pattern). Therefore they have a temporary relationship.
To keep track of all the references to an object, AspectJ supports field set pointcut. Yet, I think it would be nice if we also have the set pointcut for local variables since an object could refer to other objects through its local variable.
Thank you for your comments!
Sunny