Re: DI/wiring
On 4/18/13 11:56 AM, Joerg Meier wrote:
On 18 Apr 2013 16:03:21 GMT, Stefan Ram wrote:
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.
Change the methods to setPrinter and setEngine instead, and use Lombok. And
just like that, your boilerplate is reduced to
@Data class Bla {
private Engine engine;
private Printer printer;
}
Liebe Gruesse,
Joerg
Thanks for the pointer to Lombok!
If only I was still programming in Java professionally, this would come
in very handy! Too bad my company is switching to PHP. No flames
please, all the arguments have been made and vetoed already ;-(.