Logo

dev-resources.site

for different kinds of informations.

The Power of Liskov Substitution Principle in Improving Software Design

Published at
2/14/2023
Categories
solid
liskov
lsp
liskovsubstitutionalprincip
Author
asifzcpe
Author
8 person written this
asifzcpe
open
The Power of Liskov Substitution Principle in Improving Software Design

The Liskov Substitution Principle (LSP) is a principle of object-oriented programming and a part of the SOLID design principles. It states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program.

A real-life business scenario where the Liskov Substitution Principle can be applied is in a banking system.

Consider a superclass "Account" with subclasses "Savings Account" and "Checking Account".

The Account class could have methods such as "deposit()" and "withdraw()".

Image description

All subclasses of Account, including Savings Account and Checking Account, can provide their own implementation of the deposit() and withdraw() methods, as the rules for depositing and withdrawing money may be different for each type of account.

Image description

Image description

Now, let's say that we have a function that accepts an Account object and performs some operations, such as depositing or withdrawing money.

If we pass a Savings Account object to this function, it should work just as well as if we had passed a Checking Account object.

This is because all of these objects are substitutable for each other, and the function should not care about the specific type of Account it is working with as long as it implements the deposit() and withdraw() methods.

Image description

Now, we can conclude that objects of subclasses can be used interchangeably with objects of the superclass without causing any problems or affecting the correctness of the program, even in a real business scenario.

lsp Article's
30 articles in total
Favicon
How to Setup Vim for Kotlin Development
Favicon
Managing LSPs in Neovim: Enable/Disable for the Entire Session
Favicon
Integrating the ruff language server
Favicon
Series Belajar Solid Principle - Liskov Substitution Principle (LSP)
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Implementing Payment Gateways with the Liskov Substitution Principle
Favicon
SOLID Principles: Liskov Substitution Principle (LSP)
Favicon
Configure Helix to use ElixirLS
Favicon
The Power of Liskov Substitution Principle in Improving Software Design
Favicon
Neovim config from scratch (Part II)
Favicon
Neovim config from scratch (Part I)
Favicon
Integrating a Language Server (LSP) in a VS Code Extension
Favicon
My Neovim setup for React, TypeScript, Tailwind CSS, etc
Favicon
How i setup neovim for speed up React, Js, Ts, etc
Favicon
Solve nvim lsp denols vs tsserver clash
Favicon
Perl Navigator - Language Server for Perl
Favicon
Neovim LSP Setup + Code Completion Engine
Favicon
NeoVim: init.lua, built in LSP e mais
Favicon
How to fix [deno-ts 2339] in the code for Deno Deploy
Favicon
SOLID e o princรญpio do 6 por meia dรบzia
Favicon
Java LSP in Sublime Text
Favicon
Neovim: Migrando do coc.vim para nvim-lsp
Favicon
Integrating Scala Metals with Doom Emacs using LSP on Pop!_OS/Ubuntu 20.04 LTS
Favicon
Builtin Solidity Language Server
Favicon
Liskov Substitution Principle
Favicon
Emacs as SQL client with LSP
Favicon
Vim Configuration from Minimal to Complete
Favicon
LSP and ISP: The LI of SOLID
Favicon
Go LSP in Sublime Text

Featured ones: