Prev | Current Page 575 | Next

Frank Zammetti

"Practical DWR 2 Projects"


Spring Dependency Injection (IoC)
No, Dependency Injection, or DI for short, is not what happens when you marry someone that
already has kids . . . nor is it anything you should be afraid to speak of in mixed company. It??™s a
development pattern that basically says that instead of leaving a given class to instantiate all
the other classes it depends on, let some container ???inject??? these dependencies into the class
at the point of instantiation. The idea is to write less code, of course, and also to reduce coupling
between classes (that part is only true to some extent, in my opinion, since the class still
has to know about its dependencies, but it has to know less, which is good). DI is also referred
to as Inversion of Control, or IoC, which is actually the name of the pattern being implemented.
Both terms can generally be used interchangeably.
Spring was, if not the first, then certainly the implementation of this pattern that raised it
to prominence. Spring has evolved over time to be a much richer platform encompassing much
more than just IoC, but that??™s what it started out as, and what it really became popular as.
This is going to be a long chapter, so it won??™t be possible to go into great detail on DI, but I
want to give you at least a brief overview of it.


Pages:
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587