V
VisionSet
I have code like below.
When I deserialize my Parent object my 2 references to my 'A' object will
become independent references to separate objects.
My work round is as below, with the dual updates to the 'A' object, but that
update is not trivial and it seems daft to do it twice.
When I get an update I could recopy accross the reference to 'A' but that
destroys my 'final' elegance.
What are my options / usual solutions to this kind of thing?
TIA,
Mike W
class Parent {
private final Child c;
private final A a;
Parent() {
a = new A();
c = new Child(a);
}
void update(Parent p) {
a.update(p.a);
c.update(p.c);
}
}
class Child {
private final A a;
Child(A _a) {
a = _a;
}
void update(Child c) {
a.update(c.a); // don't want to do this
}
}
When I deserialize my Parent object my 2 references to my 'A' object will
become independent references to separate objects.
My work round is as below, with the dual updates to the 'A' object, but that
update is not trivial and it seems daft to do it twice.
When I get an update I could recopy accross the reference to 'A' but that
destroys my 'final' elegance.
What are my options / usual solutions to this kind of thing?
TIA,
Mike W
class Parent {
private final Child c;
private final A a;
Parent() {
a = new A();
c = new Child(a);
}
void update(Parent p) {
a.update(p.a);
c.update(p.c);
}
}
class Child {
private final A a;
Child(A _a) {
a = _a;
}
void update(Child c) {
a.update(c.a); // don't want to do this
}
}