Category Archives: Design Principles

Service Locator Pattern

According to Wikipedia “The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry known as the “service locator”, which on request returns the information necessary to perform a certain task.” We can simplify the definition as follows: »   … Read More »

Dependency Injection – Interface Injection

What is Interface Injection? »    Also known as Method injection. »    In this case Dependency declared inside the dependent class in the form of interface. »    So any class that implements that interface can be substituted into dependent class. »    Dependency is injected as the parameter of method. »    Useful where the whole class does… Read More »

Dependency Injection – Setter Injection

What is Setter Injection? »    Also known as Property Injection. »    We pass dependencies through setter property. »    In this case there is no need of constructor for passing dependencies »    Just need property of dependency class. »    Used when a class has optional dependencies, »    Also used where the implementations may need to be… Read More »

Dependency Injection- Constructor Injection

What is Constructor Injection? »    Provably most common Dependency Injection (DI) »    Pass dependencies to the dependent class through its constructor. »    In this case dependent class doesn’t contain any default constructor. So in order to initialize the dependent class we have to pass concrete implementation of interface. »    Injected component can be used anywhere… Read More »

Dependency Injection (DI)

According to Wikipedia “Dependency injection is a software design pattern that implements Inversion of Control (IoC) and allows a program design to follow the dependency inversion principle (DIP).”  »    Dependency Injection (DI) is a design pattern that demonstrates how to create loosely coupled classes. »    It implements Inversion of Control (IoC) in our program i.e. Dependency Injection (DI) supply the dependencies… Read More »

Dependency Inversion Principle

According to Uncle Bob Martin: A. “High-level modules should not depend on low-level modules. Both should depend on abstractions.” B. “Abstractions should not depend on details. Details should depend on abstractions.” So we can easily explain it as follows: »    The Dependency Inversion principle (DIP) decouples lower level objects from higher level objects. »    To… Read More »

Inversion of Control (IoC)

According to Wikipedia “Inversion of Control (IoC) is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming” We can simplify it as follows: »    IoC is a programming style where a framework or runtime controls the program… Read More »

Gentle Introduction of Dependency

What is Dependency? In programming dependency is the relationship between »    One class with another class or interface, »    One module with another module, »    One method with another method »    One method with another class or interface and so forth.  Consider following scenario: »    Whenever a class A uses another class or interface B,… Read More »

Interface Segregation Principle

According to Wikipedia “No client should be forced to depend on methods it does not use”  According to Uncle Bob Martin “Clients should not be forced to depend upon interfaces that they do not use”  »    If there are multiple responsibilities represented by an interface then it becomes difficult to know which methods should be… Read More »

Liscov Substitution Principle

Barbara Liscov defined this principle as follows: “If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.” According to Uncle Bob Martin… Read More »