SlideShare a Scribd company logo
1 of 25
Introduction
A Little background
Maulik Soni
Few Terminologies
 Basic OOP
 Cohesion
 Coupling
 Code Smells
 Design Smells
 Technical Debt
Maulik Soni
Cohesion
 Cohesion refers to what the class (or module) will do
 Try to achieve High Cohesion
Maulik Soni
Coupling
 How related are two classes / modules and how dependent they are on each other
 Try to achieve Loose Coupling
Maulik Soni
Code Smells
 Duplicate code
 Long method
 Large class
 Temporary field
 Switch statements
 Parallel inheritance hierarchies
Maulik Soni
Design Smells
 Rigidity
 Software is difficult to change
 Fragility
 Program breaks in many places when a change mode in a single place
 Immobility
 Parts could be useful in other systems, but effort and risk to separate from original system is too
great.
Maulik Soni
Design Smells
 Viscosity
 Design-preserving methods are more difficult to use than the hacks
 Development environment is slow and inefficient
 Needless complexity
 Contains elements that aren’t currently useful
 Needless repetition
 System has lots of repeated code elements
 Opacity
 A module is difficult to understand
Maulik Soni
Technical Debt
 The cost to fix rotting code
 Interest charges build over time
 The longer we take to remove the smells, the more it will cost
Maulik Soni
End of Introduction
 So Now, Let’s begin…
Maulik Soni
SOLID Principles - I
SRP – Single Responsibility Principle
O/CP – Open Closed Principle
Maulik Soni
What are SOLID Principles ?
 Single responsibility
 Open-closed
 Liskov substitution
 Interface segregation
 Dependency inversion
Maulik Soni
First five principles named by Robert C Martin in early 2000.
Why SOLID ?
 When Applied together it creates a system
 Easy to Maintain
 Easy to Extend over time
 To remove the Code Smells
 Part of overall strategy of agile and adaptive programming
Maulik Soni
Why Solid ? Another View
Maulik Soni
 To Deliver Fast
 To manage changes easily
 To deal with complexity
Single Responsibility Principle
 A software module should have one and only one responsibility
Maulik Soni
Example
Maulik Soni
Is SRP Violated Here ?
Maulik Soni
Is SRP Violated Here ?
Maulik Soni
Real world SRP
Maulik Soni
SRP - Summary
 SRP is the simplest of the principles, and one of the hardest to get right
 We tend to join responsibilities together
 It's usually hard to see different responsibilities
Maulik Soni
Open / Closed Principle
 All systems change during their life cycles
 avoid a cascade of changes to dependent modules
 When requirements change, you extend the behavior, not changing old code
Maulik Soni
Open / Closed Principle
 Software Entities ( Classes, Modules, Functions Etc.) Should be open for extension but
closed for modification
 Open for extension
 Behavior of the module can be extended
 We are able to change what the module does
 Closed for modification
 Extending behavior does not result in changes to source, binary, or code of the module
Maulik Soni
Is O/CP Violated Here ?
Maulik Soni
Solution
Maulik Soni
Open / Closed Rule of Thumb
 Use IF/SWITCH statements if number of cases are
unlikely to change
 Use strategy pattern when number of cases are likely
to change
 Don’t code for situations that you won’t ever need
 More smaller class files != more complicated code
Maulik Soni
End of Presentation
Maulik Soni

More Related Content

Similar to SOLID Principles Part 1

Is your code solid
Is your code solidIs your code solid
Is your code solidNathan Gloyn
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxhreempandya
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionKnoldus Inc.
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desaijinaldesailive
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design PatternsFaizan Haider
 
Getting Started with the Joomla! Framework
Getting Started with the Joomla! FrameworkGetting Started with the Joomla! Framework
Getting Started with the Joomla! FrameworkMichael Babker
 
OOSCM. Object Oriented SCM
OOSCM. Object Oriented SCMOOSCM. Object Oriented SCM
OOSCM. Object Oriented SCMESUG
 
Code Smells Part 1: Basic Smells
Code Smells Part 1:  Basic SmellsCode Smells Part 1:  Basic Smells
Code Smells Part 1: Basic SmellsNancy Henson
 
Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUGlburdz
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design PatternsLiraz Shay
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship ChecklistRyan Polk
 
Dev Ops Essentials Course
Dev Ops Essentials CourseDev Ops Essentials Course
Dev Ops Essentials CourseUse DevOps
 

Similar to SOLID Principles Part 1 (20)

Soild principles
Soild principlesSoild principles
Soild principles
 
Is your code solid
Is your code solidIs your code solid
Is your code solid
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test Automaion
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Solid
SolidSolid
Solid
 
Template pattern
Template patternTemplate pattern
Template pattern
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
Getting Started with the Joomla! Framework
Getting Started with the Joomla! FrameworkGetting Started with the Joomla! Framework
Getting Started with the Joomla! Framework
 
OOSCM. Object Oriented SCM
OOSCM. Object Oriented SCMOOSCM. Object Oriented SCM
OOSCM. Object Oriented SCM
 
Lowenthal Moodle Changing The Face Of Corporate Learning
Lowenthal Moodle Changing The Face Of Corporate LearningLowenthal Moodle Changing The Face Of Corporate Learning
Lowenthal Moodle Changing The Face Of Corporate Learning
 
Code Smells Part 1: Basic Smells
Code Smells Part 1:  Basic SmellsCode Smells Part 1:  Basic Smells
Code Smells Part 1: Basic Smells
 
Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
 
spring aop
spring aopspring aop
spring aop
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship Checklist
 
Dev Ops Essentials Course
Dev Ops Essentials CourseDev Ops Essentials Course
Dev Ops Essentials Course
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

SOLID Principles Part 1

  • 2. Few Terminologies  Basic OOP  Cohesion  Coupling  Code Smells  Design Smells  Technical Debt Maulik Soni
  • 3. Cohesion  Cohesion refers to what the class (or module) will do  Try to achieve High Cohesion Maulik Soni
  • 4. Coupling  How related are two classes / modules and how dependent they are on each other  Try to achieve Loose Coupling Maulik Soni
  • 5. Code Smells  Duplicate code  Long method  Large class  Temporary field  Switch statements  Parallel inheritance hierarchies Maulik Soni
  • 6. Design Smells  Rigidity  Software is difficult to change  Fragility  Program breaks in many places when a change mode in a single place  Immobility  Parts could be useful in other systems, but effort and risk to separate from original system is too great. Maulik Soni
  • 7. Design Smells  Viscosity  Design-preserving methods are more difficult to use than the hacks  Development environment is slow and inefficient  Needless complexity  Contains elements that aren’t currently useful  Needless repetition  System has lots of repeated code elements  Opacity  A module is difficult to understand Maulik Soni
  • 8. Technical Debt  The cost to fix rotting code  Interest charges build over time  The longer we take to remove the smells, the more it will cost Maulik Soni
  • 9. End of Introduction  So Now, Let’s begin… Maulik Soni
  • 10. SOLID Principles - I SRP – Single Responsibility Principle O/CP – Open Closed Principle Maulik Soni
  • 11. What are SOLID Principles ?  Single responsibility  Open-closed  Liskov substitution  Interface segregation  Dependency inversion Maulik Soni First five principles named by Robert C Martin in early 2000.
  • 12. Why SOLID ?  When Applied together it creates a system  Easy to Maintain  Easy to Extend over time  To remove the Code Smells  Part of overall strategy of agile and adaptive programming Maulik Soni
  • 13. Why Solid ? Another View Maulik Soni  To Deliver Fast  To manage changes easily  To deal with complexity
  • 14. Single Responsibility Principle  A software module should have one and only one responsibility Maulik Soni
  • 16. Is SRP Violated Here ? Maulik Soni
  • 17. Is SRP Violated Here ? Maulik Soni
  • 19. SRP - Summary  SRP is the simplest of the principles, and one of the hardest to get right  We tend to join responsibilities together  It's usually hard to see different responsibilities Maulik Soni
  • 20. Open / Closed Principle  All systems change during their life cycles  avoid a cascade of changes to dependent modules  When requirements change, you extend the behavior, not changing old code Maulik Soni
  • 21. Open / Closed Principle  Software Entities ( Classes, Modules, Functions Etc.) Should be open for extension but closed for modification  Open for extension  Behavior of the module can be extended  We are able to change what the module does  Closed for modification  Extending behavior does not result in changes to source, binary, or code of the module Maulik Soni
  • 22. Is O/CP Violated Here ? Maulik Soni
  • 24. Open / Closed Rule of Thumb  Use IF/SWITCH statements if number of cases are unlikely to change  Use strategy pattern when number of cases are likely to change  Don’t code for situations that you won’t ever need  More smaller class files != more complicated code Maulik Soni

Editor's Notes

  1. Cohesion refers to what the class will do. Low cohesion would mean that the class does a great verity of actions and is not focused on what it should do. High cohesion would then mean that the class is focused on what it should be doing. I.e only method relating to the intention of the class.
  2. Tight Coupling – A class has a direct reference to a concrete class Loose Coupling – A class has a reference to an Abstraction which can be implemented by one or more classes. Benefits – Testability - Easier to test objects in isolation Reuse – dependencies can be swapped without modifying the target Applies Open / Closed Principle – change behavior without modifying the target
  3. SOLID  is a mnemonic acronym introduced by Michael Feathers. Five basic principles of object-oriented programming and design.
  4. The principles, when applied together, intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time.[3] The principles of SOLID are guidelines that can be applied while working on software to remove code smells by causing the programmer to refactor the software's source code until it is both legible and extensible. It is part of an overall strategy of agile andadaptive programming
  5. every class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its servicesshould be narrowly aligned with that responsibility.
  6. Martin defines a responsibility as a reason to change, and concludes that a class or module should have one, and only one, reason to change. As an example, consider a module that compiles and prints a report. Imagine such a module can be changed for two reasons. First, the content of the report could change. Second, the format of the report could change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
  7. identify things that are changing for  different reasons group together things that change for the  same reason SRP requires very precise names, very  focused classes
  8. identify things that are changing for  different reasons group together things that change for the  same reason SRP requires very precise names, very  focused classes
  9. theorized in 1998 by Bertrand Meyer in a  classical OO book
  10. Q : Is it possible to add new shape without changing the draw () method ? Yes. See it in next slide.
  11. Abstraction is the key! keep the things that change frequently  away from things that don't change Rely on abstractions Interfaces Abstract classes Whenever I see switch statements, there is possible place to apply o/CP and some design patterns.
  12. This is the end of the presentation of SOLID principles. SRP and OCP. Hope next time when you come across code similar to this slide, you will at-least think is it violating any SOLID principles ?