Dependency Injection

We have seen earlier in this chapter that we were sending a Datasource object into the constructor method of our UserDAO object, to provide the connection details for the datasource.

This is an object-oriented programming technique used to provide information to a specific object for it to work with.

Essentially, Dependency Injection (DI) controls what information an object has access to, and therefore, what information it has to work with. Traditionally in procedural programming, an object may have access to information from a variety of sources, and the object itself may have the ability to access and digest this information as needed.

Using Dependency Injection in your object-oriented programming is a highly effective way to control this information; the technique is also known as Inversion of Control (IoC).

This means that the control over what your object receives is inverted and instead of grabbing whatever it needs, the object is provided or fed only the information or data it is allowed to use. As a result it only uses that information it has been given.

Dependency Injection

Displaying Dependency Injection using the UML guidelines is incredibly simple. To emphasize a dependency between objects, we join them using a dotted line with an arrowhead, as shown in the previous image.

For a more detailed look into the technique of Dependency Injection, please visit the following wiki site:

http://www.objectorientedcoldfusion.org/wiki/Dependency_Injection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.198.94