Define Inversion of Control?

984    Asked by SoniaLewis in Python , Asked on Jan 2, 2020
Answered by Arun Singh

Inversion of control is an associate expansive term but for a product engineer it's most frequently delineates as an example utilised for decoupling segments and layers within the framework.

For instance, say your application contains a content tool section and you wish to administer spell checking. Your customary code would look one thing like this:

public class TextEditor {

private SpellChecker checker;

open TextEditor() {

this.checker = new SpellChecker();

}

}

What we've done here makes a reliance between the TextEditor and therefore the SpellChecker. In associate IoC state of affairs we might rather accomplish one thing like this:

public class TextEditor {

private IocSpellChecker checker;

public TextEditor(IocSpellChecker checker) {

this.checker = checker;

}

}

You have inverted management by giving the duty of popping out the spell checker from the TextEditor category to the caller.

SpellChecker sc = new SpellChecker; //dependency

TextEditor textEditor = new TextEditor(sc);



Your Answer

Interviews

Parent Categories