AngularJS Essentials
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Dependency Injection<br />
and Services<br />
Cohesion is one of the most important and perhaps overlooked concepts of the<br />
object-oriented programming paradigm. It refers to the responsibility of each part of<br />
the software. No matter which component we talk about, every time it implements<br />
behavior different from its responsibilities, cohesion is degraded.<br />
Low cohesion applications contain plenty of duplicated code and are hard to unit<br />
test because it is difficult to isolate the behavior, which is usually hidden inside the<br />
component. It also reduces the reuse opportunities, demanding much more effort to<br />
implement the same thing several times. In the long term, the productivity decreases<br />
while the maintenance costs are raised.<br />
With <strong>AngularJS</strong>, we are able to create services, isolating the business logic of every<br />
component of our application. Also, we can use the framework's dependency<br />
injection mechanism to easily supply any component with a desired dependency.<br />
The framework also comes with a bunch of built-in services, which are very useful in<br />
daily development.<br />
In this chapter, we'll be covering the following topics:<br />
• Dependency injection<br />
• Creating services<br />
• Using <strong>AngularJS</strong> built-in services<br />
www.it-ebooks.info