{"id":20264263,"url":"https://github.com/kawser2133/solid-design-principles","last_synced_at":"2026-03-08T05:32:20.139Z","repository":{"id":183362598,"uuid":"670010355","full_name":"kawser2133/SOLID-design-principles","owner":"kawser2133","description":"Mastering SOLID Principles in Software Design: A Blueprint for Clean and Maintainable Code","archived":false,"fork":false,"pushed_at":"2024-08-31T06:15:19.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T21:48:02.645Z","etag":null,"topics":["clean-code","object-oriented-design","programming-tips","software-architecture","software-development","solid-principles"],"latest_commit_sha":null,"homepage":"https://binarybytez.com/mastering-solid-design-principles/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kawser2133.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-24T05:17:22.000Z","updated_at":"2025-02-09T07:27:07.000Z","dependencies_parsed_at":"2025-01-14T04:44:38.298Z","dependency_job_id":"005d10c5-ca91-467a-87d0-b48c091d4f86","html_url":"https://github.com/kawser2133/SOLID-design-principles","commit_stats":null,"previous_names":["kawser2133/solid-design-principles"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kawser2133/SOLID-design-principles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FSOLID-design-principles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FSOLID-design-principles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FSOLID-design-principles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FSOLID-design-principles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kawser2133","download_url":"https://codeload.github.com/kawser2133/SOLID-design-principles/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FSOLID-design-principles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30246727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-code","object-oriented-design","programming-tips","software-architecture","software-development","solid-principles"],"created_at":"2024-11-14T11:38:51.310Z","updated_at":"2026-03-08T05:32:20.097Z","avatar_url":"https://github.com/kawser2133.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mastering SOLID Principles in Software Design\n\nIn the dynamic world of software development, writing maintainable and scalable code is crucial to the success of any project. [SOLID design principles](https://binarybytez.com/mastering-solid-design-principles/) provide a set of guidelines that can help developers achieve precisely that. Developed by Robert C. Martin (Uncle Bob), these principles have become a cornerstone of modern software architecture. In this post, I will explore each SOLID principle in depth, understand its significance, and learn how to apply them effectively with practical coding examples. \n\nYou can visit my blog post- [Mastering SOLID Design Principles: A Blueprint for Clean Code](https://binarybytez.com/mastering-solid-design-principles/)\n\n## 1. Single Responsibility Principle (SRP):\n\nThe Single Responsibility Principle emphasizes that a class should have only one reason to change. In other words, a class should have a single responsibility or task. By adhering to SRP, we ensure that each class has a clear purpose, making the code more modular, maintainable, and easier to understand.\n\nLet's illustrate SRP with an example:\n\n```csharp\n// Bad Practice - One class with multiple responsibilities\nclass OrderProcessingService\n{\n    public void ProcessOrder(Order order)\n    {\n        // ... Process the order ...\n    }\n\n    public void SendEmailConfirmation(Order order)\n    {\n        // ... Send email confirmation ...\n    }\n\n    public void GenerateInvoice(Order order)\n    {\n        // ... Generate the invoice ...\n    }\n}\n```\n\n```csharp\n// Good Practice - Separate classes with single responsibility\nclass OrderProcessor\n{\n    public void ProcessOrder(Order order)\n    {\n        // ... Process the order ...\n    }\n}\n\nclass EmailService\n{\n    public void SendEmailConfirmation(Order order)\n    {\n        // ... Send email confirmation ...\n    }\n}\n\nclass InvoiceGenerator\n{\n    public void GenerateInvoice(Order order)\n    {\n        // ... Generate the invoice ...\n    }\n}\n```\n\n## 2. Open-Closed Principle (OCP):\n\nThe Open-Closed Principle suggests that software entities should be open for extension but closed for modification. By using interfaces, we adhere to OCP and create more flexible and adaptable systems that can be easily extended without altering existing code.\n\nLet's see how to apply OCP:\n\n```csharp\n// Bad Practice - Modifying existing class\nclass Shape\n{\n    public virtual double Area()\n    {\n        // ... Calculate area ...\n    }\n}\n\nclass Circle : Shape\n{\n    public override double Area()\n    {\n        // ... Calculate circle area ...\n    }\n}\n\nclass Square : Shape\n{\n    public override double Area()\n    {\n        // ... Calculate square area ...\n    }\n}\n```\n\n```csharp\n// Good Practice - Extending behavior through interfaces\ninterface IShape\n{\n    double Area();\n}\n\nclass Circle : IShape\n{\n    public double Area()\n    {\n        // ... Calculate circle area ...\n    }\n}\n\nclass Square : IShape\n{\n    public double Area()\n    {\n        // ... Calculate square area ...\n    }\n}\n```\n\n## 3. Liskov Substitution Principle (LSP):\n\nThe Liskov Substitution Principle emphasizes that objects of derived classes should be substitutable for objects of the base class without affecting program correctness. By following LSP, we ensure that derived classes can seamlessly replace their base class counterparts, promoting code consistency and maintainability.\n\nLet's maintain LSP:\n\n```csharp\n// Bad Practice - Violating LSP\nclass Bird\n{\n    public virtual void Fly()\n    {\n        // ... Fly like a bird ...\n    }\n}\n\nclass Penguin : Bird\n{\n    public override void Fly()\n    {\n        throw new NotSupportedException(\"Penguins cannot fly.\");\n    }\n}\n```\n\n```csharp\n// Good Practice - Upholding LSP\ninterface IFlyable\n{\n    void Fly();\n}\n\nclass Bird : IFlyable\n{\n    public void Fly()\n    {\n        // ... Fly like a bird ...\n    }\n}\n\nclass Penguin : IFlyable\n{\n    public void Fly()\n    {\n        // Penguins cannot fly, but still conform to the interface.\n    }\n}\n```\n\n## 4. Interface Segregation Principle (ISP):\n\nThe Interface Segregation Principle advises segregating interfaces into smaller, focused ones, rather than having large, monolithic interfaces. By adhering to ISP, we create leaner and more focused interfaces, enabling better code maintainability and adaptability.\n\nLet's implement ISP:\n\n```csharp\n// Bad Practice - Large, monolithic interface\ninterface IWorker\n{\n    void Work();\n    void Eat();\n    void Sleep();\n}\n\nclass Robot : IWorker\n{\n    // Implementing unnecessary methods for a robot.\n}\n\nclass Human : IWorker\n{\n    // Implementing unnecessary methods for a human.\n}\n```\n\n```csharp\n// Good Practice - Segregated interfaces\ninterface IWorkable\n{\n    void Work();\n}\n\ninterface IEatable\n{\n    void Eat();\n}\n\ninterface ISleepable\n{\n    void Sleep();\n}\n\nclass Robot : IWorkable\n{\n    public void Work()\n    {\n        // ... Robot work logic ...\n    }\n}\n\nclass Human : IWorkable, IEatable, ISleepable\n{\n    public void Work()\n    {\n        // ... Human work logic ...\n    }\n\n    public void Eat()\n    {\n        // ... Human eat logic ...\n\n\n    }\n\n    public void Sleep()\n    {\n        // ... Human sleep logic ...\n    }\n}\n```\n\n## 5. Dependency Inversion Principle (DIP):\n\nThe Dependency Inversion Principle suggests relying on abstractions rather than concrete implementations. By following DIP, we promote loose coupling and enable easier testing, extensibility, and a more modular design.\n\nLet's apply DIP:\n\n```csharp\n// Bad Practice - High-level module depends on low-level module\nclass OrderProcessor\n{\n    private readonly EmailService _emailService;\n\n    public OrderProcessor()\n    {\n        _emailService = new EmailService();\n    }\n    \n    public void ProcessOrder(Order order)\n    {\n        // ... Process the order ...\n        _emailService.SendEmailConfirmation(order);\n    }\n}\n```\n\n```csharp\n// Good Practice - High-level module depends on abstraction\ninterface IEmailService\n{\n    void SendEmailConfirmation(Order order);\n}\n\nclass EmailService : IEmailService\n{\n    public void SendEmailConfirmation(Order order)\n    {\n        // ... Send email confirmation ...\n    }\n}\n\nclass OrderProcessor\n{\n    private readonly IEmailService _emailService;\n\n    public OrderProcessor(IEmailService emailService)\n    {\n        _emailService = emailService;\n    }\n    \n    public void ProcessOrder(Order order)\n    {\n        // ... Process the order ...\n        _emailService.SendEmailConfirmation(order);\n    }\n}\n```\n\nIncorporating [SOLID principles](https://binarybytez.com/mastering-solid-design-principles/) in your software development journey can be transformational. These principles empower developers to write cleaner, more maintainable, and extensible code, resulting in robust and scalable software solutions. As you apply SRP, OCP, LSP, ISP, and DIP in your projects, you'll witness the growth of your coding prowess and the emergence of truly clean code that stands the test of time. Embrace [SOLID](https://binarybytez.com/mastering-solid-design-principles/) principles and elevate your coding skills to new heights! Thanks\n\n_This post is based on examples from [Clean Structured Project](https://github.com/kawser2133/clean-structured-project) and [Web API Project](https://github.com/kawser2133/web-api-project) repositories on GitHub._\n\n## Authors\n\nIf you have any questions or need further assistance, please contact the project author at [@kawser2133](https://www.github.com/kawser2133) || [![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white)](https://www.linkedin.com/in/kawser2133)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawser2133%2Fsolid-design-principles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkawser2133%2Fsolid-design-principles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawser2133%2Fsolid-design-principles/lists"}