S.O.L.I.D is an acronym for the first five object-oriented design(OOD) principles .These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend. They also make it easy for developers to avoid code smells, easily refactor code, and are also a part of the agile or adaptive software development.
IoC - Inversion of Control
- SRP - Single Responsibility Principle
- A class should have only one reason to change
- OCP - Open/Close Principle
- A class should be open to extension but close for modification
- LSP - Liskov Substitution Principle
- If any module is using a Base class then the reference to that Base class can be replaced with a Derived class without affecting the functionality of the module.
- You should be able to replace a class with a subclass without the calling code knowing about the change
- ISP - Interface Segregation Principle
- that clients should not be forced to implement interfaces they don't use. Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one sub module.
- Many specific interfaces are better than a single
- DIP - Dependency Inversion Principle
- Code should depend upon abstractions, not concrete implementations
IoC - Inversion of Control
- IoC is a design principle which recommends the inversion of different kinds of controls in object-oriented design to achieve loose coupling between application classes
- Inversion of Control (IoC) is a design principle (although, some people refer to it as a pattern). As the name suggests, it is used to invert different kinds of controls in object-oriented design to achieve loose coupling. Here, controls refer to any additional responsibilities a class has, other than its main responsibility. This include control over the flow of an application, and control over the flow of an object creation or dependent object creation and binding.
- suppose you drive a car to your work place. This means you control the car. The IoC principle suggests to invert the control, meaning that instead of driving the car yourself, you hire a cab, where another person will drive the car. Thus, this is called inversion of the control - from you to the cab driver. You don't have to drive a car yourself and you can let the driver do the driving so that you can focus on your main work.
- It allows the creation of dependent objects outside of a class and provides those objects to a class through different ways. Using DI, we move the creation and binding of the dependent objects outside of the class that depends on them.
- The Dependency Injection pattern involves 3 types of classes.
- Client Class: The client class (dependent class) is a class which depends on the service class
- Service Class: The service class (dependency) is a class that provides service to the client class.
- Injector Class: The injector class injects the service class object into the client class.
No comments:
Post a Comment