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.
Monday, June 16, 2025
Sign in / Join
  • Contact Us
  • Our Team
Facebook
Instagram
Twitter
Vimeo
Youtube
Logo
  • Home
  • News
    • News

      Pixel Phones Just Got Smarter With New AI Features by Penka Hristovska

      16 June 2025
      News

      FBI Warns About A Spike In Hacked Police Emails by Tyler Cross

      16 June 2025
      News

      Officials: Trump Not Signing Transitional Agreement Presents Cybersecurity Concern by Tyler Cross

      16 June 2025
      News

      Bitcoin Fog Operator Sentenced to 12.5 Years for Laundering Over $400 Million by Penka Hristovska

      16 June 2025
      News

      ExpressVPN Partners with Tottenham Hotspur to Enhance Digital Security by Manual Thomas

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

      Why Your Vibe Coding Generates Outdated Code and How to Fix It with Milvus MCP

      16 June 2025
      Big data

      Vespa Newsletter, January 2023

      15 June 2025
      Big data

      Vespa Newsletter, May 2023

      15 June 2025
      Big data

      Vespa support in langchain

      15 June 2025
    • Big data
    • Business Analytics
    • Databases
    • Data Structure & Algorithm
    • Data Science
    • Deep Learning
    • Ethical Hacking
    • Generative AI
    • Machine Learning
    • Security & Testing
  • Mobile
    • AllAndroidIOS
      IOS

      Dopamine developer warns of issues affecting certain devices after installing latest Procursus updates, offers solution

      16 June 2025
      IOS

      Jailbreak news of the week: Dopamine jailbreak updates, hack enables animated icons, & more…

      16 June 2025
      IOS

      Dopamine v2.1.6 update brings more bug fixes and improvements

      16 June 2025
      IOS

      At least one checkm8-vulnerable iPad still supported by iPadOS 18

      16 June 2025
    • Android
    • IOS
  • Languages
    • AllAjaxAngularDynamic ProgrammingGolangJavaJavascriptPhpPythonReactVue
    • Java
    • Python
  • 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

      Interview With Dr. Arash Rafii Tabriz – Founder at ScieNFT by Shauli Zacks

      16 June 2025
      Guest Blogs

      What Is a Dark Web Scan? Your Complete Guide for 2025 by Christopher Owolabi

      16 June 2025
      Guest Blogs

      What Is Android Safe Mode? Complete Guide in 2025 (All Androids) by Marlene Baiton

      16 June 2025

      LEAVE A REPLY Cancel reply

      Log in to leave a comment

      Most Popular

      Dopamine developer warns of issues affecting certain devices after installing latest Procursus updates, offers solution

      16 June 2025

      Jailbreak news of the week: Dopamine jailbreak updates, hack enables animated icons, & more…

      16 June 2025

      Dopamine v2.1.6 update brings more bug fixes and improvements

      16 June 2025

      At least one checkm8-vulnerable iPad still supported by iPadOS 18

      16 June 2025
      Load more
      Algomaster
      Algomaster
      184 POSTS0 COMMENTS
      https://blog.algomaster.io
      Calisto Chipfumbu
      Calisto Chipfumbu
      273 POSTS0 COMMENTS
      http://cchipfumbu@gmail.com
      Dominic
      Dominic
      244 POSTS0 COMMENTS
      http://wardslaus.com
      Milvus
      Milvus
      54 POSTS0 COMMENTS
      https://milvus.io/
      Nango Kala
      Nango Kala
      290 POSTS0 COMMENTS
      neverop
      neverop
      0 POSTS0 COMMENTS
      https://geeksforgeeks.org
      Nicole Veronica
      Nicole Veronica
      296 POSTS0 COMMENTS
      Nokonwaba Nkukhwana
      Nokonwaba Nkukhwana
      327 POSTS0 COMMENTS
      Safety Detectives
      Safety Detectives
      376 POSTS0 COMMENTS
      https://www.safetydetectives.com/
      Shaida Kate Naidoo
      Shaida Kate Naidoo
      272 POSTS0 COMMENTS
      Ted Musemwa
      Ted Musemwa
      326 POSTS0 COMMENTS
      Thapelo Manthata
      Thapelo Manthata
      513 POSTS0 COMMENTS
      Umr Jansen
      Umr Jansen
      262 POSTS0 COMMENTS

      EDITOR PICKS

      Dopamine developer warns of issues affecting certain devices after installing latest Procursus updates, offers solution

      16 June 2025

      Jailbreak news of the week: Dopamine jailbreak updates, hack enables animated icons, & more…

      16 June 2025

      Dopamine v2.1.6 update brings more bug fixes and improvements

      16 June 2025

      POPULAR POSTS

      Dopamine developer warns of issues affecting certain devices after installing latest Procursus updates, offers solution

      16 June 2025

      Jailbreak news of the week: Dopamine jailbreak updates, hack enables animated icons, & more…

      16 June 2025

      Dopamine v2.1.6 update brings more bug fixes and improvements

      16 June 2025

      POPULAR CATEGORY

      • Languages35875
      • Python15899
      • Data Structure & Algorithm12243
      • Java7584
      • Javascript6359
      • Php3791
      • Machine Learning2192
      • Android1862
      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