A puzzling architectural question: You have two symmetrical classes A
and B
. Each A
/B
object may privately produce a value of type IA
/IB
using the A.CreateIA()
/B.CreateIB()
methods. These values are needed by the opposite classes - A
needs IB
and B
needs IA
.
The goal is to write the PairMaker.MakePair()
function that constructs an interlinks a pair of A
and B
objects. You also have to write appropriate constructors for the A
and B
classes. A
and B
classes are in different assemblies and don't see each other's internals. The link should be secure - the external code should not be able to access or modify the object fields. You can write additional classes and add any methods to A
and B
as needed - just don't break the security of the link.
interface IA { }
interface IB { }
class A {
IB ib;
//Some constructor
//Other members
IA CreateIA() { }
}
class B {
IA ia;
//Some constructor
//Other members
IB CreateIB() { }
}
class PairMaker {
public static Tuple<A, B> MakePair() {
//What's here?
}
}
This question is similar to How to construct two objects, with each other as a parameter/member, but that question wasn't answered properly.
Update: Please note, that this problem IS solvable (as you can write any constructors you want). Please don't downvote or close this question just because you cannot devise a solution.
Here is a possible solution. I don't like how it looks (I hate those
out
parameters in the constructors)..