- S - Single Responsibility Principle
- O - Open Closed Principle
- L - Liskov Substitution Principle
- I - Interface Segregation Principle
- D - Dependency Inversion Principle
S : Single Responsibility Principle
A class should be responsible for a single part of the functionality.
- Their should never be more than one reason for class to change.
- A class should have only one job to perform.
- Chance of any one class containing bug is lower, therefor change is less fragile.
- Classes becomes smaller and cleaner.
- Simpler to understand and maintain.
O : Open Closed Principle
- Open to extension
- Closed for Modification
- Use interfaces
- Limits the need to change code once it has been tested and debugged.
- Reduces risks of introducing new bugs.
- Reduced coupling
L : Liskov Substitution Principle
Liskov substitution, also known as "Substitutability". You should be able to use a subclass in a place of its parent class.
- Use derived class without knowing it.
- Sub-classes must operate in the same manner as their base class.
I : Interface Segregation Principle
A class should not depend on methods that it does not need to implement.
- Classes may have interfaces that are not cohesive.
- Clients should not be forced to depend upon interfaces they do not use.
- ISP recommends multiple, smaller, cohesive interfaces.
- Interfaces become tightly focused.
- Easier to implement.
D : Dependency Inversion Principal
Your classes and modules should depend on abstraction instead of concrete implementations.
- High level modules should not depend on low level modules, both should depend on abstractions.
- Client should not be forced to depend upon interfaces they do not use.
- DIP removes direct dependencies between classes.
- Classes become loosely coupled, making it easier to substitute alternative implementations.
What is OOP?
- An object is a thing.
- Objects have properties and methods.
- Properties are bits of data.
- Methods effect or manipulate the data.
- Objects have or implement certain characteristics - Encapsulation, Polymorphism and Inheritance.
Encapsulation :
- Ensures an object groups all necessary properties and methods for a particular object. Eg. a Customer might have Name and Address properties - and these would be defined within the Customer object itself.
- Objects can contain other objects - for example a Customer might contain an Address object that has Street, City and Pin Code properties.
Inheritance :
- Objects can extend other object.
- A Person object may define common properties and methods - a Customer may inherit that Person object and add new properties and methods.
- Resultant object contain all properties and methods of both the 'base' object and the new object.
Polymorphism :
- Two objects may have the same properties and methods but implement them differently.
- Use of interfaces to define properties and methods - the signature.
- Any object that implement the interface can be freely swapped in and out for each other without breaking the code.
JSON Generator : Awesome tool for generating random #JSON data at Json-generator
A simple JSON store for your web or mobile app: myjson