|
|
|
|
|
by munificent
4315 days ago
|
|
Let's say your app my_app uses foo and bar. They both use baz. You give them each their own version of baz: foo gets baz 1.0 and bar gets baz 2.0. Now, at runtime: my_app calls foo.giveMeAWidget()
foo calls new baz.Widget() on its 1.0.0 version of baz
my_app gets that back
then it calls bar.doSomethingWithAWidget(widget) and passes it in
bar calls baz.flummoxAWidget(widget) and passes the widget in
baz.flummoxAWidget() starts doing stuff with the widget
The last step is bad. You have baz 2.0.0 code that assumes it has a baz 2.0.0 widget, but it's actually a 1.0.0 one. It could work, crash, or fail in some subtle way.Note that this isn't statically detectable. It's based on how objects flow around in memory at runtime. Now, in cases where you don't pass objects around like this, you'll avoid this problem. But it's really hard to tell when that's the case and when it isn't. |
|
What you're describing is an inappropriate intimacy antipattern.