A
Andersen
Is there an idiom or pattern for creating two objects (a and b) of two
different classes A and B, such that A contains a reference to b and B
contains a reference to a. Should I pass it through a constructor? In
that case, when creating A, I cannot give the constructor a reference to
b since b has not yet been created (or vice versa if b is created first).
Should I have set methods in both where I can set these variables? Then
I have the problem that one might forget to set it, and the object is in
a bad state.
regards,
Andersen
different classes A and B, such that A contains a reference to b and B
contains a reference to a. Should I pass it through a constructor? In
that case, when creating A, I cannot give the constructor a reference to
b since b has not yet been created (or vice versa if b is created first).
Should I have set methods in both where I can set these variables? Then
I have the problem that one might forget to set it, and the object is in
a bad state.
regards,
Andersen