'Substitution Principle' By Barbara Liskov
Relation Depicted By Parent & Child

'Substitution Principle' By Barbara Liskov

~ One of the most important SOLID Principle, well known for its capability to increase efficiency in OOP Language like Java - 'Liskov's Substitution Principle' can be described in two statements :-

  1. If for each object 1 of type S there is an object 2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when 1 is substituted for 2 then S is a subtype of T.
  2. Subtypes must be substitutable for their base types.

~ Suppose, in Java coding terms, we should distribute classes into parent - child relationship. By using Java's Major Pillar - Inheritance, we can keep some common methods in parent class / interface and can be implemented in the child classes.

~ For example :-

Account - CurrentAccount / SavingsAccount Relationship


API Gateway - Microservices Relationship

~ The above example can be considered as one of the pragmatic example in Web Development. In which, Microservices can be programmed using LSP. The reason why we usually have to replace a microservice is that there is a new version of it. So, if my entity is a microservice, the equivalent entity is the new version of it. So, applying LSP to microservices, we don’t want to break existing clients of the service, but replace it with a better or enhanced one.


~ Benefits Of LSP :-

  1. Reusability :- Code can be reused quite easily with such a valuable concept and can save time for use.
  2. Interchangeability :- We can create a set of related classes that can be used interchangeably without modifying the code.








要查看或添加评论,请登录

Somesh Dahotre的更多文章

  • BYOIP

    BYOIP

    About Bring Your Own IP :- Bring Your Own IP enables customers to assign IP Addresses from a public IP Range that they…

  • Spring Data JPA

    Spring Data JPA

    JpaRepository is a JPA (Java Persistence API) specific extension of Repository. It contains the full API of…

  • Checked These Java 21 Updates ?

    Checked These Java 21 Updates ?

    Latest Java Version 21 was updated on 19th September, 2023 with Long Term Support (LTS) from Oracle. This version has…

  • Heard About XaaS ?

    Heard About XaaS ?

    'Xaas' encompasses many technologies and tools that are provided by vendors as a service over the internet, as opposed…

  • Builder Design Pattern

    Builder Design Pattern

    There are various design patterns followed in the IT / Development Industry with the main objective of increasing…

  • Stability Of Sorting Algorithm

    Stability Of Sorting Algorithm

    Stability of the sorting algorithm plays an important role in time / space complexities. An algorithm is said to be…

  • Still Struggling With Scaling ?

    Still Struggling With Scaling ?

    'Horizontal Pod AutoScaler' made the scaling far superior than before. The name 'AutoScaler' itself suggests that it'll…

  • MicroServices

    MicroServices

    ~ Small independent services that communicate over well-defined APIs are titled as ' Microservices '. As microservices…

  • ASP.NET Core Web App Flow Diagram

    ASP.NET Core Web App Flow Diagram

    ' Separation Of Concern, Dependency Inversion Principle, Single Responsibility Principle, Open For Extension - Close…

    2 条评论
  • Developers + IT Operations + Testers

    Developers + IT Operations + Testers

    Development and Operations, may be two different words, But not anonymous after all. DevOps is basically a culture to…

社区洞察

其他会员也浏览了