SlideShare a Scribd company logo
1 of 26
Download to read offline
SOLID PRINCIPLES
with Ruby examples
By Nhan Nguyen (nhanntit)
ROBERT C. MARTIN
“Clean code is not written by
following a set of rules. You
don’t become a software
craftsman by learning a list
of heuristics. Professionalism
and craftsmanship come
from values that drive
disciplines.”
Clean Code: A Handbook of Agile
Software Craftsmanship
By following SOLID design
principles, developers can achieve
a maintainable and extendable
codebase
CONTENT
SINGLE RESPONSIBILITY
PRINCIPLE
A class should have a single
responsibility.
 A class’s responsibility isn’t always
immediately clear.
 Any complicated classes should be divided
into smaller classes that are each
responsible for a particular behaviour,
making it easier to understand and maintain
your codebase.
 The goal of the SR principle is to fight
complexity that creeps in while you’re
developing an application’s logic.
CHECK AN EXAMPLE
Any violation SRP?
VIOLATIONS
1. Handling two tasks:
generate_report!, send_report
2. May be problematic in
expanding in the future: have
to change the logic of the class
REFACTORED
1. Separate classes
2. Changing the logic of the class
without touching the remaining
class
OPEN-CLOSED PRINCIPLE
Modules, classes, methods and
other application entities should be
open for extension but closed for
modification.
 The codebase of software projects is often
modified throughout their lifetimes.
Therefore, a developer’s goal should be to
build a flexible system that is easy to modify
and extend.
 All modules, classes, methods, etc. should
be designed in a modular way, so that we
are able to change the behavior of the
system without changing the source code.
CHECK AN EXAMPLE
Any violation OCP?
VIOLATIONS
1. We’ll have to modify the logger
every time we need to add
additional senders or formatters
REFACTORED
1. Segregated senders and formatters to
separate classes
2. Enabled the addition of new senders and
formatters without having to modify the base
code
LISKOV SUBSTITUTION
PRINCIPLE
Subclasses should add to a base
class’s behaviour, not replace it.
 The principle states that parent instances
should be replaceable with one of their
child instances without creating any
unexpected or incorrect behavior.
 LSP ensures that abstractions are correct,
and helps developers achieve more
reusable code and better organize class
hierarchies
CHECK AN EXAMPLE
Any violation LSP?
VIOLATIONS
1. The child class violates the LSP
principle since it completely
redefines the base class by
returning a string with filtered
data, whereas the base class
returns an array of posts.
REFACTORED
1. Segregated the filtration logic
and the statistics string
generation logic into two
methods: “posts“ and
“formatted_posts“
THE INTERFACE SEGREGATION
PRINCIPLE
Clients shouldn’t depend on
methods they don’t use. Several
client-specific interfaces are better
than one generalized interface.
 Main classes should be segregated into
smaller specific classes, so their clients use
only methods they need.
 We get the interfaces segregated
according to their purpose, so we avoid
“fat” classes and code that’s hard to
maintain.
CHECK AN EXAMPLE
Any violation ISP?
VIOLATIONS
1. Existing the unused methods for
an instance
REFACTORED
1. Segregated in two interfaces
with methods that perform
specific tasks
THE DEPENDENCY INVERSION
PRINCIPLE
High-level modules shouldn’t
depend on low-level modules.
 Abstractions shouldn’t depend on details.
Details depend on abstractions
 The code that follows the LSP and OCP
principles should be readable and contain
clearly separated abstractions. It should also
be extendable, and child classes should be
easily replaceable by other instances of a
base class without breaking the system.
CHECK AN EXAMPLE
Any violation DIP?
VIOLATIONS
1. The classes PdfFormatter and
HtmlFormatter may contain the
logic that refers to other
classes. Thus, we may impact
all the related classes when
modifying the class Printer
REFACTORED
1. High-level object (Printer)
doesn’t depend directly on the
implementation of low-level
objects
2. Our high-level functionality is
separated from all low-level
details, so we’re able to easily
change the low-level logic
without system-wide
implications
CONCLUSION
Applied correctly, SOLID design
recommendations can help you
build system architecture that is
easy to modify and extend over
time
 Saying “Now my code conforms to SOLID
design principles” is the wrong approach.
 Remember that SOLID principles themselves
don’t guarantee great object-oriented
design.
 Apply SOLID principles smartly
RELAX
Solid principles

More Related Content

Similar to Solid principles

Sec1_SOLID Principles_Software Engineering.pptx
Sec1_SOLID Principles_Software Engineering.pptxSec1_SOLID Principles_Software Engineering.pptx
Sec1_SOLID Principles_Software Engineering.pptxHebaSamy22
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principlesrainynovember12
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsBasavaraj Patil
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignIrwansyah Irwansyah
 
Software Design Principles (SOLID)
Software Design Principles (SOLID)Software Design Principles (SOLID)
Software Design Principles (SOLID)ASIMYILDIZ
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Leekas Shep
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerKaterina Trajchevska
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesBruno Bossola
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patternsPrabhakar Sharma
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of ControlShuhab Tariq
 
Is your code solid
Is your code solidIs your code solid
Is your code solidNathan Gloyn
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design PatternsFaizan Haider
 

Similar to Solid principles (20)

Sec1_SOLID Principles_Software Engineering.pptx
Sec1_SOLID Principles_Software Engineering.pptxSec1_SOLID Principles_Software Engineering.pptx
Sec1_SOLID Principles_Software Engineering.pptx
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Solid principes
Solid principesSolid principes
Solid principes
 
Solid
SolidSolid
Solid
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Software Design Principles (SOLID)
Software Design Principles (SOLID)Software Design Principles (SOLID)
Software Design Principles (SOLID)
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Solid
SolidSolid
Solid
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developer
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design Principles
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
 
Case study 1
Case study 1Case study 1
Case study 1
 
Is your code solid
Is your code solidIs your code solid
Is your code solid
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 

More from Nhan Nguyen

Agile planning and monitoring
Agile planning and monitoringAgile planning and monitoring
Agile planning and monitoringNhan Nguyen
 
Product quality in agile project
Product quality in agile projectProduct quality in agile project
Product quality in agile projectNhan Nguyen
 
Retrospective in action
Retrospective in actionRetrospective in action
Retrospective in actionNhan Nguyen
 
SCRUM and Poker Game In Agile Project
SCRUM and Poker Game In Agile ProjectSCRUM and Poker Game In Agile Project
SCRUM and Poker Game In Agile ProjectNhan Nguyen
 
Continuous integration - CI
Continuous integration - CIContinuous integration - CI
Continuous integration - CINhan Nguyen
 

More from Nhan Nguyen (6)

Scrum Framework
Scrum FrameworkScrum Framework
Scrum Framework
 
Agile planning and monitoring
Agile planning and monitoringAgile planning and monitoring
Agile planning and monitoring
 
Product quality in agile project
Product quality in agile projectProduct quality in agile project
Product quality in agile project
 
Retrospective in action
Retrospective in actionRetrospective in action
Retrospective in action
 
SCRUM and Poker Game In Agile Project
SCRUM and Poker Game In Agile ProjectSCRUM and Poker Game In Agile Project
SCRUM and Poker Game In Agile Project
 
Continuous integration - CI
Continuous integration - CIContinuous integration - CI
Continuous integration - CI
 

Recently uploaded

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Solid principles

  • 1. SOLID PRINCIPLES with Ruby examples By Nhan Nguyen (nhanntit)
  • 2. ROBERT C. MARTIN “Clean code is not written by following a set of rules. You don’t become a software craftsman by learning a list of heuristics. Professionalism and craftsmanship come from values that drive disciplines.” Clean Code: A Handbook of Agile Software Craftsmanship
  • 3. By following SOLID design principles, developers can achieve a maintainable and extendable codebase CONTENT
  • 4. SINGLE RESPONSIBILITY PRINCIPLE A class should have a single responsibility.  A class’s responsibility isn’t always immediately clear.  Any complicated classes should be divided into smaller classes that are each responsible for a particular behaviour, making it easier to understand and maintain your codebase.  The goal of the SR principle is to fight complexity that creeps in while you’re developing an application’s logic.
  • 5. CHECK AN EXAMPLE Any violation SRP?
  • 6. VIOLATIONS 1. Handling two tasks: generate_report!, send_report 2. May be problematic in expanding in the future: have to change the logic of the class
  • 7. REFACTORED 1. Separate classes 2. Changing the logic of the class without touching the remaining class
  • 8. OPEN-CLOSED PRINCIPLE Modules, classes, methods and other application entities should be open for extension but closed for modification.  The codebase of software projects is often modified throughout their lifetimes. Therefore, a developer’s goal should be to build a flexible system that is easy to modify and extend.  All modules, classes, methods, etc. should be designed in a modular way, so that we are able to change the behavior of the system without changing the source code.
  • 9. CHECK AN EXAMPLE Any violation OCP?
  • 10. VIOLATIONS 1. We’ll have to modify the logger every time we need to add additional senders or formatters
  • 11. REFACTORED 1. Segregated senders and formatters to separate classes 2. Enabled the addition of new senders and formatters without having to modify the base code
  • 12. LISKOV SUBSTITUTION PRINCIPLE Subclasses should add to a base class’s behaviour, not replace it.  The principle states that parent instances should be replaceable with one of their child instances without creating any unexpected or incorrect behavior.  LSP ensures that abstractions are correct, and helps developers achieve more reusable code and better organize class hierarchies
  • 13. CHECK AN EXAMPLE Any violation LSP?
  • 14. VIOLATIONS 1. The child class violates the LSP principle since it completely redefines the base class by returning a string with filtered data, whereas the base class returns an array of posts.
  • 15. REFACTORED 1. Segregated the filtration logic and the statistics string generation logic into two methods: “posts“ and “formatted_posts“
  • 16. THE INTERFACE SEGREGATION PRINCIPLE Clients shouldn’t depend on methods they don’t use. Several client-specific interfaces are better than one generalized interface.  Main classes should be segregated into smaller specific classes, so their clients use only methods they need.  We get the interfaces segregated according to their purpose, so we avoid “fat” classes and code that’s hard to maintain.
  • 17. CHECK AN EXAMPLE Any violation ISP?
  • 18. VIOLATIONS 1. Existing the unused methods for an instance
  • 19. REFACTORED 1. Segregated in two interfaces with methods that perform specific tasks
  • 20. THE DEPENDENCY INVERSION PRINCIPLE High-level modules shouldn’t depend on low-level modules.  Abstractions shouldn’t depend on details. Details depend on abstractions  The code that follows the LSP and OCP principles should be readable and contain clearly separated abstractions. It should also be extendable, and child classes should be easily replaceable by other instances of a base class without breaking the system.
  • 21. CHECK AN EXAMPLE Any violation DIP?
  • 22. VIOLATIONS 1. The classes PdfFormatter and HtmlFormatter may contain the logic that refers to other classes. Thus, we may impact all the related classes when modifying the class Printer
  • 23. REFACTORED 1. High-level object (Printer) doesn’t depend directly on the implementation of low-level objects 2. Our high-level functionality is separated from all low-level details, so we’re able to easily change the low-level logic without system-wide implications
  • 24. CONCLUSION Applied correctly, SOLID design recommendations can help you build system architecture that is easy to modify and extend over time  Saying “Now my code conforms to SOLID design principles” is the wrong approach.  Remember that SOLID principles themselves don’t guarantee great object-oriented design.  Apply SOLID principles smartly
  • 25. RELAX