Simple Factory Design Pattern doesn’t belong to the Gangs of Four. A Simple Factory Pattern is one of that returns an instance of one of several possible classes, depending on the data provided to it. This implies that the classes it returns have same parent class and methods, but each of them perform task differently for different kind of data. Continue Reading>>
Design patterns were introduced by GOF(Gangs Of Four) Erich Gamma, Richard Helm, Ralph Johnson,
and John Vlissides’s seminal work Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley).
Design patterns provide a high-level language of discourse for programmers to describe their systems and to discuss solutions to common problems. This language comprises the names of recognizable patterns and their elements. Each design pattern shave its own templates and these patterns have illustrative names and are described with diagrams illustrating, their role players. There are 23 design patterns. These patterns are divided into three groups: structural, creational, and behavioral. Continue Reading>>
So, there are a lot of confusion in developers mind regarding Dependency Inversion Principle, Dependency Injection and Inversion of Control, that’s why I tried to explain as par my experience. We need to understand a bit of Software Design Principle & Software Design Pattern. Dependency Inversion Principle (DIP) is a Software design principle and Inversion of Control (IoC) is a Software design pattern. Let's see what is Software design principle and pattern.
Software Design Principle:
Principle provides us only guideline to achieve some task. Principle tells us what is right and what is wrong. It doesn’t say us how to solve problem. It just gives some guideline so that we can design good software and avoid bad design. Some principles are DRY, OCP, DIP etc.Continue Reading>>
Inversion of control (IoC) describes a design in which custom-written portions of a computer program receive the flow of control from a generic, reusable library. A software architecture with this design inverts control as compared to traditional procedural programming: in traditional programming, the custom code that expresses the purpose of the program calls into reusable libraries to take care of generic tasks, but with inversion of control, it is the reusable code that calls into the custom, or problem-specific, code.
Let's try to understand the inversion of control in with an example. Suppose, we have a console application with a sequence of commands like "Enter name", "enter address"; this program would drive the prompts and pick up a response to each one. With graphical (or even screen based) UIs the UI framework would contain this main loop and your program instead provided event handlers for the various fields on the screen. The main control of the program was inverted, moved away from you to the framework.
We have discussed Dependency Injection (DI) as a separate article; here we only try to know the core concept of Dependency Injection (DI). A type of IoC where we move the creation and binding of dependency outside of the class that depends on it. In normal object are created inside of the dependent class and bounded inside the dependent class. In Dependency Injection (DI) it is done from outside of the dependent class. There are three type of Dependency Injection (DI).
- Setter Injection
- Interface Injection