I'm wondering about the best solution (maybe pattern) to this problem: I have 2 classes that have reference to the same object
class A {
...
}
class X {
A objectA;
}
class Y {
A objectA;
}
the problem is how to keep these reference even when one class X or Y assingn new object. For example
class Y {
A objectA;
private void doSomething(){
objectA = new A();
}
}
at this point the object X has deprecated reference, but I would like it to be aware of this change. Passing references to each other is unacceptable, so object X can not be aware of object Y.
EDIT: This pattern can exist in my appliaction more than once so I can't use Singleton