Inversion of control

From Wikipedia, the free encyclopedia

Inversion of Control, also known as IOC, is an object-oriented programming principle that can be used to reduce coupling inherent in computer programmes.

IOC is also known as the Dependency Injection (Martin 2002:127). The Dependency injection (Fowler 2004) technique is used in almost every framework and it is a simple example of the IoC principle applied. It has been applied by programmers using object-oriented programming languages such as Smalltalk, C++, Java or any .NET language.

Contents

Class X depends on class Y if any of the following applies:

X depends on Y does not imply Y depends on X. If both happen to be true this is called a cyclic dependency: X can't then be used without Y, and vice versa.

Inversion of control relates to the way in which an object obtains references to its dependencies. This is often done by a lookup method. This approach has the disadvantage that an explicit dependence is introduced on a particular lookup mechanism, so the caller is dependent on a particular environment as well as on the object it obtains. With inversion of control the object is passed its dependencies through constructor arguments or after construction through setter methods. The approach is also called 'dependency injection' since the dependences of an object are 'injected' into it.

The advantage of inversion of control is that it decouples objects from specific lookup mechanisms and implementations of the objects it depends on. As a result, more flexibility is obtained for production applications as well as for testing. In particular, dependencies on a particular deployment environment can be removed from the code making it much easier to test functionality in a simple standalone environment. A consequence of this is that it becomes faster and easier to test so that in the end quality of the software is improved.

ColdSpring uses an Inversion-of-Control pattern and an Aspect-Oriented-Programming (AOP) framework for ColdFusion components (CFC).

Groovy on Grails uses Spring Framework to initialize the application.

Programmers using the Java programming language have applied Inversion of Control in an Inversion of Control Container (Martin 2004). The software requests an object from the container and the container builds the object and its dependencies. The ATG Dynamo application server was one of the first environments to leverage this approach, while more recent examples of these containers include HiveMind, PicoContainer, Spring Framework (note that Spring is a complete enterprise platform, not just an IOC container), Apache Excalibur, Seasar, and DPML Metro.

  1. ^  Robert Cecil Martin (2002). Agile Software Development: Principles, Patterns and Practices. Pearson Education. ISBN 0-13-597444-5. 
  2. ^  Robert Cecil Martin. The Dependency Inversion Principle (PDF). Retrieved on November 15, 2005.
  3. ^  Martin Fowler (2004). Inversion of Control Containers and the Dependency Injection Pattern. Retrieved on November 15, 2005.
  4. ^  Sony Mathew (2005). Examining the Validity of Inversion of Control. Retrieved on November 16, 2005.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.