What is Inversion of Control?
public class TextEditor {
private SpellChecker checker;
public TextEditor() {
this.checker = new SpellChecker();
}
}
public class TextEditor {
private IocSpellChecker checker;
public TextEditor(IocSpellChecker checker) {
this.checker = checker;
}
}
SpellChecker sc = new SpellChecker(); // dependency
TextEditor textEditor = new TextEditor(sc);
Tags: oop design-patterns inversion-of-control
Source: By Mike Minutillo as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0
Related code-snippets:
- Is Object Property accessible from within object method?
- How can we add a method to an existing Object Instance?
- Pass by reference or pass by value?
- What's the difference between MVC and MVP?
- How do you create a sparse array?
- How do I create a class using Singleton Design Pattern in Ruby?
- Accessing a CONST attribute of series of classes by default a class that is a series of classes.
- Why do Active Record Hate?
- What is the best way to create objects in Perl?
- What are your favorite ways of interacting with databases from a programming language?
- Custom WPF command pattern example.
- What's the best way to create a static class in C++?
- Need pattern for dynamic search of multiple sql tables?
- Inheritance and polymorphism - Ease of use vs Purity. Inheritance and polymorphism - Ease of use vs Purity of use.
- Access to Global Application Settings for Linux.