Single Responsibility Principle – SOLID

One thing will have only one responsibilities to do thing

It state that there should not be more than one responsibility or dependency on one thing, and It should have one reason to change.

Every object should have single responsibility, and that responsibility should be entirely encapsulated by the class – Wikipedia 

There should never be more then one reason for a class to change -Robert C. “Uncle Bob” Martine 

Let’s have an example, where this is violating the rule than will correct the issue.

    public class Sale
    {
        public void ProcessOrder()
        {
            // Product price calculation and their quentity

            // Reduce the stock or inventory 

            // Place the order

            // Order to be assign to Customer 
        }
    }

Here we can see there is lots of activity is happening in one place, rather it should be divided into sub module or parts.

Here we can see how we can divided this using the Interface:

public class Sale
{
    private readonly IPriceCalculator priceCalculator;
    private readonly IStockManager stockManager;
    private readonly IPlaceOrder placeOrder;
    private readonly IAssignOrdertoCustomer assignOrdertoCustomer;

    public Sale(IPriceCalculator priceCalculator, 
        IStockManager stockManager, 
        IPlaceOrder placeOrder, 
        IAssignOrdertoCustomer assignOrdertoCustomer)
    {
        this.priceCalculator = priceCalculator;
        this.stockManager = stockManager;
        this.placeOrder = placeOrder;
        this.assignOrdertoCustomer = assignOrdertoCustomer;
    }
    public void ProcessOrder()
    {
        priceCalculator.CalculatePrice();

        stockManager.UpdateInventory();

        placeOrder.OrderPlace();

        assignOrdertoCustomer.Assign();
    }
}

SOLID Principles in simple word

SOLID is acronym of these word:
* Single Responsibility Principal
* Open Closed Principal
* Liskov  Substitution Principal
* Interface Segregation Principal
* Dependency Inversion Principal 

Single Responsibility Principal 
> One thing will have only one responsibilities to do thing
> Every object should have single responsibility, and that responsibility should be entirely encapsulated by the class – Wikipedia 
> There should never be more then one reason for a class to change -Robert C. “Uncle Bob” Martine 

Open Close Principal 
> Open for Extension but close for modification
> The Open/Closed Principal states that software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification -Wikipedia 

Liskov  Substitution Principal 
> Subs type should be substitutable for their base type
>  If S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e. an object of type T may be substituted with any object of a subtype S) without altering any of the desirable properties of the program (correctness, task performed, etc.) – Wikipedia 

The Interface Segregation Principal 
> Interface should have only things (method) which all the client suppose to use otherwise segregate those things (method) which might not be used by client in separate Interface  
> No client should be forced to depend on methods it does not use.[1] ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them – Wikipedia

Dependency Inversion Principal
> High-level modules should not depend on low-level modules. Both should depend on abstraction.
> Abstraction should not depend on details. Details should depend on abstractions.