SOLID Principles and OOP Concepts

SOLID Principles and OOP Concepts

SOLID Principles :

  • 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


Have a nice day!

To view or add a comment, sign in

More articles by Manish Kumar

  • Learning Jasmine and NUnit

    Jasmine website : Jasmine documentation : jQuery matchers Jasmine plugin : To install jasmine at Global level : npm…

  • Website to Learn From

    I have no TV Online library : Become an author for packtpub . Internet Radio : Fitness : Asteroid Database and Mining…

  • Web Development Part 2: Useful Learning Resources

    Understanding the Node.js event loop Bootstrap forms : Body parser : Functions : async.

  • Web development Part 1: Angular and Git

    Angular 1 : Released in October 2010 Angular 2 : Released in 2015 and is build using TypeScript. Features: Performance…

  • Understanding Webpack

    On npmjs website webpack package is described as "webpack is a module bundler. Its main purpose is to bundle JavaScript…

  • Base64 Encoder

    ASCII String : Manish ASCII Character Codes : m -109 and M - 077 077-097-110-105-115-104 8-bit Binary Character Codes :…

  • Angular Basics

    Angular is a JavaScript Framework which allows us to create reactive Single-Page-Applications ( SPA ). Angular…

  • Salesforce Lightning : Attribute

    In the lightning component, write below code: Here v = view, displayMessage is the name of attribute. <aura:component >…

  • Salesforce Lightning : Student Registration Form

    In the StudentRegistrationFormComponent.cmd component, write below code : <!-- StudentRegistrationFormComponent…

Others also viewed

Explore content categories