Keeping simplicity ... 1. If Foo should always know myInteger from Bar, pass it to the constructor.
2. If Foo only occasionally needs to know myInteger, then call the setter after the constructor.
If Foo requires more than myInteger, i.e. the whole Bar object, then Bar can pass itself using the keyword "this".
public class Foo
{
public Foo(Bar bar)
{
}
}
// Somewhere in the bar (in the non-stationary method)
new Foo (this);
source
share