Facebook Instagram Twitter Vimeo Youtube
Sign in
  • Home
  • About
  • Team
  • Buy now!
Sign in
Welcome!Log into your account
Forgot your password?
Privacy Policy
Password recovery
Recover your password
Search
Logo
Sign in
Welcome! Log into your account
Forgot your password? Get help
Privacy Policy
Password recovery
Recover your password
A password will be e-mailed to you.
Thursday, October 16, 2025
Sign in / Join
  • Contact Us
  • Our Team
Facebook
Instagram
Twitter
Vimeo
Youtube
Logo
  • Home
  • News
    • News

      Cloudflare Thwarts Record-Breaking 22.2 Tbps DDoS Attack by Paige Henley

      3 October 2025
      News

      Ransomware Attack Hits Major European Airports via Collins Aerospace Software by Husain Parvez

      3 October 2025
      News

      Steam Pulls Game After Malware Steals Over $150,000 in Crypto by Husain Parvez

      3 October 2025
      News

      Mexican Senate Advances Framework for National Cybersecurity Law by Husain Parvez

      1 October 2025
      News

      CBK Launches Sector-Wide Cybersecurity Centre Amid Rising Attacks by Husain Parvez

      27 September 2025
  • Data Modelling & AI
    • AllBig dataBusiness AnalyticsData ScienceData Structure & AlgorithmDatabasesVector DatabaseDeep LearningEthical HackingGenerative AIMachine Learning
      Big data

      Smarter Retrieval for RAG: Late Chunking with Jina Embeddings v2 and Milvus

      15 October 2025
      Big data

      From Word2Vec to LLM2Vec: How to Choose the Right Embedding Model for RAG

      8 October 2025
      Big data

      How to Debug Slow Search Requests in Milvus

      4 October 2025
      Big data

      When Context Engineering Is Done Right, Hallucinations Can Be the Spark of AI Creativity

      2 October 2025
    • Big data
    • Business Analytics
    • Databases
    • Data Structure & Algorithm
    • Data Science
    • Deep Learning
    • Ethical Hacking
    • Generative AI
    • Machine Learning
    • Security & Testing
  • Mobile
    • AllAndroidIOS
      Android

      Google is working on dedicated ‘Bills’ and ‘Travel’ folders for Gmail

      15 October 2025
      Android

      Mint Mobile’s big bet on 5G home internet might change everything

      15 October 2025
      Android

      Honor’s new Robot Phone concept is giving DJI Pocket fans something to look forward to

      15 October 2025
      Android

      Spotify’s AI DJ goes bilingual, while podcasts get set to make the jump to Netflix

      15 October 2025
    • Android
    • IOS
  • Languages
    • AllAjaxAngularDynamic ProgrammingGolangJavaJavascriptPhpPythonReactVue
      Languages

      Working with Titles and Heading – Python docx Module

      25 June 2025
      Languages

      Creating a Receipt Calculator using Python

      25 June 2025
      Languages

      One Liner for Python if-elif-else Statements

      25 June 2025
      Languages

      Add Years to datetime Object in Python

      25 June 2025
    • Java
    • Python
    • Ajax
    • Php
    • Python
    • Golang
    • Dynamic Programming
    • React
    • Vue
    • Java
    • Javascript
    • NodeJS
    • Angular
  • Guest Blogs
  • Discussion
  • Our Team
HomeData Modelling & AIBig dataS.O.L.I.D Principles Explained With Code
Big dataGuest Blogs

S.O.L.I.D Principles Explained With Code

Algomaster
By Algomaster
15 June 2025
0
0
Share
Facebook
Twitter
Pinterest
WhatsApp

    S.O.L.I.D Principles Explained With Code

    #3 Low Level Design – SOLID Principles

    Ashish Pratap Singh's avatar

    Ashish Pratap Singh
    Mar 17, 2024

    Writing clean, maintainable code is just as important as writing code that works.

    The SOLID principles provide a blueprint for writing code that’s easy to adjust, extend, and maintain over time.

    It was introduced by Robert C. Martin (Uncle Bob) in the early 2000s.

    In this article, we will explore each of the 5 principles with real world examples and code:


    If you’re finding this newsletter valuable and want to deepen your learning, consider becoming a paid subscriber.

    As a paid subscriber, you’ll receive an exclusive deep-dive article every week, access to a structured System Design Resource (100+ topics and interview questions), and other premium perks.

    Unlock Full Access


    S: Single Responsibility Principle (SRP)

    A class should have one, and only one, reason to change.

    This means that a class must have only one responsibility.

    When a class performs just one task, it contains a small number of methods and member variables making them more usable and easier to maintain.

    If a class has multiple responsibilities, it becomes harder to understand, maintain, and modify and increases the potential for bugs because changes to one responsibility could affect the others.

    Code Example:

    Imagine you have a class called UserManager that handles user authentication, user profile management, and email notifications.

    This class violates the SRP because it has multiple responsibilities: authentication, profile management, and email notifications.

    If you need to change the way user authentication is handled, you might inadvertently affect the email notification logic, or vice versa.

    To adhere to the SRP, we can split this class into three separate classes, each with a single responsibility:

    Now, each class has a single, well-defined responsibility. Changes to user authentication won’t affect the email notification logic, and vice versa, improving maintainability and reducing the risk of unintended side effects.


    O: Open/Closed Principle (OCP)

    Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

    This means the design of a software entity should be such that you can introduce new functionality or behavior without modifying the existing code since changing the existing code might introduce bugs.

    Code Example:

    Let’s say you have a ShapeCalculator class that calculates the area and perimeter of different shapes like rectangles and circles.

    If we want to add support for a new shape, like a triangle, we would have to modify the calculate_area and calculate_perimeter methods, violating the Open/Closed Principle.

    To adhere to the OCP, we can create an abstract base class for shapes and separate concrete classes for each shape type:

    By introducing an abstraction (Shape class) and separating the concrete implementations (Rectangle and Circle classes), we can add new shapes without modifying the existing code.

    The ShapeCalculator class can now work with any shape that implements the Shape interface, allowing for easy extensibility.


    L: Liskov Substitution Principle (LSP)

    Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program.

    This means if you have a base class and a derived class, you should be able to use instances of the derived class wherever instances of the base class are expected, without breaking the application.

    Code Example:

    Let’s consider a scenario where we have a base class Vehicle and two derived classes Car and Bicycle.

    Without following the LSP, the code might look like this:

    In this example, the Bicycle class violates the LSP because it provides an implementation for the start_engine method, which doesn’t make sense for a bicycle.

    If we try to substitute a Bicycle instance where a Vehicle instance is expected, it might lead to unexpected behavior or errors.

    To adhere to the LSP, we can restructure the code as follows:

    Here, we’ve replaced the start_engine method with a more general start method in the base class Vehicle. The Car class implements the start method to start the engine, while the Bicycle class implements the start method to indicate that the rider is pedaling.

    Now, instances of Car and Bicycle can be safely substituted for instances of Vehicle without any unexpected behavior or errors.

    Share


    I: Interface Segregation Principle (ISP)

    No client should be forced to depend on interfaces they don’t use.

    The main idea behind ISP is to prevent the creation of “fat” or “bloated” interfaces that include methods that are not required by all clients.

    By segregating interfaces into smaller, more specific ones, clients only depend on the methods they actually need, promoting loose coupling and better code organization.

    Code Example:

    Let’s consider a scenario where we have a media player application that supports different types of media files, such as audio files (MP3, WAV) and video files (MP4, AVI).

    Without applying the ISP, we might have a single interface like this:

    In this case, any class that implements the MediaPlayer interface would be forced to implement all the methods, even if it doesn’t need them.

    For example, an audio player would have to implement the play_video, stop_video, and adjust_video_brightness methods, even though they are not relevant for audio playback.

    To adhere to the ISP, we can segregate the interface into smaller, more focused interfaces:

    Now, we can have separate implementations for audio and video players:

    By segregating the interfaces, each class only needs to implement the methods it actually requires. This not only makes the code more maintainable but also prevents clients from being forced to depend on methods they don’t use.

    If we need a class that supports both audio and video playback, we can create a new class that implements both interfaces:


    D: Dependency Inversion Principle (DIP)

    High-level modules should not depend on low-level modules; both should depend on abstractions.

    This means that a particular class should not depend directly on another class, but on an abstraction (interface) of this class.

    Applying this principle reduces dependency on specific implementations and makes our code more reusable.

    Code Example:

    Let’s consider a example where we have a EmailService class that sends emails using a specific email provider (e.g., Gmail).

    In this example, the EmailService class directly depends on the GmailClient class, a low-level module that implements the details of sending emails using the Gmail API.

    This violates the DIP because the high-level EmailService module is tightly coupled to the low-level GmailClient module.

    To adhere to the DIP, we can introduce an abstraction (interface) for email clients:

    Now, the EmailService class depends on the EmailClient abstraction, and the low-level email client implementations (GmailClient and OutlookClient) depend on the abstraction.

    This follows the DIP, resulting in a more flexible and extensible design.


    Thank you for reading!

    If you found it valuable, hit a like ❤️ and consider subscribing for more such content every week.

    If you have any questions or suggestions, leave a comment.

    This post is public so feel free to share it.

    Share


    P.S. If you’re finding this newsletter helpful and want to get even more value, consider becoming a paid subscriber.

    As a paid subscriber, you’ll receive an exclusive deep dive every week, access to a comprehensive system design learning resource , and other premium perks.

    Get full access to AlgoMaster

    There are group discounts, gift options, and referral bonuses available.


    Checkout my Youtube channel for more in-depth content.

    Follow me on LinkedIn, X and Medium to stay updated.

    Checkout my GitHub repositories for free interview preparation resources.

    I hope you have a lovely day!

    See you soon,
    Ashish

    Share
    Facebook
    Twitter
    Pinterest
    WhatsApp
      Previous article
      15 Types of Databases and When to Use Them
      Next article
      How to Answer a System Design Interview Problem
      Algomaster
      Algomasterhttps://blog.algomaster.io
      RELATED ARTICLES
      Guest Blogs

      Interviewed With Kyle Smith – Founder and CEO of Escalated by Shauli Zacks

      15 October 2025
      Guest Blogs

      Interview With Paul Reid – VP Adversary Research at AttackIQ by Shauli Zacks

      15 October 2025
      Guest Blogs

      45 Resources for Whistleblowers and Dissidents Around the World by Tom Read

      15 October 2025

      LEAVE A REPLY Cancel reply

      Log in to leave a comment

      Most Popular

      Google is working on dedicated ‘Bills’ and ‘Travel’ folders for Gmail

      15 October 2025

      Mint Mobile’s big bet on 5G home internet might change everything

      15 October 2025

      Interviewed With Kyle Smith – Founder and CEO of Escalated by Shauli Zacks

      15 October 2025

      Interview With Paul Reid – VP Adversary Research at AttackIQ by Shauli Zacks

      15 October 2025
      Load more
      Algomaster
      Algomaster
      202 POSTS0 COMMENTS
      https://blog.algomaster.io
      Calisto Chipfumbu
      Calisto Chipfumbu
      6745 POSTS0 COMMENTS
      http://cchipfumbu@gmail.com
      Dominic
      Dominic
      32361 POSTS0 COMMENTS
      http://wardslaus.com
      Milvus
      Milvus
      88 POSTS0 COMMENTS
      https://milvus.io/
      Nango Kala
      Nango Kala
      6728 POSTS0 COMMENTS
      neverop
      neverop
      0 POSTS0 COMMENTS
      https://geeksforgeeks.org
      Nicole Veronica
      Nicole Veronica
      11892 POSTS0 COMMENTS
      Nokonwaba Nkukhwana
      Nokonwaba Nkukhwana
      11953 POSTS0 COMMENTS
      Safety Detectives
      Safety Detectives
      2684 POSTS0 COMMENTS
      https://www.safetydetectives.com/
      Shaida Kate Naidoo
      Shaida Kate Naidoo
      6852 POSTS0 COMMENTS
      Ted Musemwa
      Ted Musemwa
      7113 POSTS0 COMMENTS
      Thapelo Manthata
      Thapelo Manthata
      6805 POSTS0 COMMENTS
      Umr Jansen
      Umr Jansen
      6801 POSTS0 COMMENTS

      EDITOR PICKS

      Google is working on dedicated ‘Bills’ and ‘Travel’ folders for Gmail

      15 October 2025

      Mint Mobile’s big bet on 5G home internet might change everything

      15 October 2025

      Interviewed With Kyle Smith – Founder and CEO of Escalated by Shauli Zacks

      15 October 2025

      POPULAR POSTS

      Google is working on dedicated ‘Bills’ and ‘Travel’ folders for Gmail

      15 October 2025

      Mint Mobile’s big bet on 5G home internet might change everything

      15 October 2025

      Interviewed With Kyle Smith – Founder and CEO of Escalated by Shauli Zacks

      15 October 2025

      POPULAR CATEGORY

      • Languages45985
      • Data Modelling & AI17573
      • Java15156
      • Android14949
      • Mobile12983
      • Guest Blogs12731
      • Javascript12713
      • Data Structure & Algorithm10077
      Logo

      ABOUT US

      We provide you with the latest breaking news and videos straight from the technology industry.

      Contact us: hello@geeksforgeeks.org

      FOLLOW US

      Blogger
      Facebook
      Flickr
      Instagram
      VKontakte

      © NeverOpen 2022

      • Home
      • News
      • Data Modelling & AI
      • Mobile
      • Languages
      • Guest Blogs
      • Discussion
      • Our Team