All options you specify are valid. Which one you choose will depend on the specific circumstances.
A constructor pattern will be the choice when B cannot exist without data from A.
The factory method would be a model of choice when the values โโof B fall depending on the values โโof A or B. Especially if B has children, that a value of B will provide a design choice.
The setter method is not applicable in your scenario, because it will be used when A and B do not know each other, and a third party must intercede.
This is essentially a visitor pattern. Visits B and leaves something by itself (thinks of bachelor days). This will be a sample if data from A is optional for B.
Philip smith
source share