Inversion of Control and how it's different from the dependency inversion principle?
If we fitting everything together it will be looks as below image.
Inversion of Control can be achieve by three ways
- Interface Inversion
- Flow inversion
- Creation Inversion
Interface should have more than one implementation.
Flow Inversion
Control of the code flow is totally inverted.
let's take an example of a command line program where program is asking for inputs one by one.
Creation Inversion is creating a object outside of the class they are being going to use. Factory pattern is the example of creation inversion.
Types of creation inversion
Flow Inversion
Control of the code flow is totally inverted.
let's take an example of a command line program where program is asking for inputs one by one.
- What's your name
- Shivam
- Whats your favorite color?
- Blue
Now I inverted the code flow to GUI and user is controlling the code flow.
Creation InversionCreation Inversion is creating a object outside of the class they are being going to use. Factory pattern is the example of creation inversion.
Types of creation inversion
- Factory Pattern
Button button = ButtonFactory.CreateButton() - Service Locator
Button button = ServiceLocator.Create(IButton.class) - Dependency Injection
Button button = GettheRightButton()
OutScreen ourscreen = new OutScreen(button);
0 comments :
Post a Comment