S
Stefan Ram
I have »invented« myself something that also seems to be
known as »dependency injection« or »wiring«. I am doing it
in pure Java SE without any framework, for example:
component0.acceptPrinter( printer0 );
component0.acceptEngine( engine0 );
component1.acceptPrinter( printer0 );
component1.acceptEngine( engine0 );
component2.acceptPrinter( printer0 );
component2.acceptEngine( engine0 );
. Now, however, every component needs to have all that
boilerplate code like an implementation of »acceptPrinter«
and so.
The whole project would need much less boilerplate, if
I would just do:
Globals.printer = printer0;
Globals.engine = engine0;
and every component that needs the printer or the engine
would just use »Globals.printer« or »Globals.engine«, just
as we use the »global« »java.lang.System.out«.
Some people, however, frown upon such globals. But would
it be that bad?
known as »dependency injection« or »wiring«. I am doing it
in pure Java SE without any framework, for example:
component0.acceptPrinter( printer0 );
component0.acceptEngine( engine0 );
component1.acceptPrinter( printer0 );
component1.acceptEngine( engine0 );
component2.acceptPrinter( printer0 );
component2.acceptEngine( engine0 );
. Now, however, every component needs to have all that
boilerplate code like an implementation of »acceptPrinter«
and so.
The whole project would need much less boilerplate, if
I would just do:
Globals.printer = printer0;
Globals.engine = engine0;
and every component that needs the printer or the engine
would just use »Globals.printer« or »Globals.engine«, just
as we use the »global« »java.lang.System.out«.
Some people, however, frown upon such globals. But would
it be that bad?