SlideShare a Scribd company logo
1 of 64
SOLID
@alfredodev
afernandez@plainconcepts.com
SOLID
• Acronim of five principles
• Principles, not laws
• A bit vague or abstract
• They are all interelated
• A bit marketing oriented (ejem Uncle Bob ;) )
• A bit criticized
• By Michael Feathers or Robert Martin
Critics
• Simple code
• Testeable code
• Low cohesion high coupling
Critics
• Simple code
• Testeable code
• Low cohesion high coupling
• Low coupling high cohesion
@gerard_lopz @quiqu3
@alfredodev
@gerard_lopz @quiqu3
@alfredodev
SOLID!
https://github.com/joebew42/study-path
SOLID
Single
Responsibility
Principle
Single
Responsibility
Principle
A class should have only
one responsibility.
Each software module
should have one and only
one reason to change.
Single
Responsibility
Principle
What is a responsibility?
Single
Responsibility
Principle
What is a reason to
change?
Example 1
Cohesion
• Cohesion refers to the degree to which the elements inside a module
belong together
Cohesion
• Cohesion refers to the degree to which the elements inside a module
belong together
Responsibilities to whom?
• Classes have responsibilities to their users, those users can be
classified into actors based on the roles that they play on the
application.
• A responsibility is a family of functions that serves a particular actor.
Example 1
Support
Banking
Tinder?
IT / operations
Single
Responsibility
Principle
What about methods?
Example 2
Tips
• Describe what the class does in one sentece (did you use the word
and or or?)
• Please Mr Object what is your Property
What are your
thoughts?
SOLID
Open
Close
Principle
Open
Close
Principle
A software module should
be open for extension and
close for modification
Change a module
behaviour without
changing its source code
Examples
Related
• Encapsulation
• Abstraction
• Dependency Inversion
What are your
thoughts?
SOLID
Liskov
Substitution
Principle
Liskov
substitution
Principle
If S is a subtype of T, then objects of type T
may be replaced with objects of type S
If the base class does something, the
inherited class must do it too and in a way
that doesn't violate the expectations of the
users of the base class
Examples
Simptoms
• Inherited class with empty methods that are implemented in the base
class
• Inherited class with that throw exceptinos
• Check If typeof (x) on the base class
I’ve fucked up
Screen
SearchScreen
ComplexSearch SimpleSearch
MaintenanceScreen
SimpleMaintenance
TabbedMaintenance
I’ve fucked up
Screen
SearchScreen
ComplexSearch SimpleSearch
MaintenanceScreen
SimpleMaintenance
TabbedMaintenance
SpecialMaintenanceWithSearch
What about dynamic languages
• Dynamic languages are different
• Duck typing
• It’s harder but the same principles should apply
Tips
• Don’t have high hirerarchies of objects
• Favor composition over inheritance
What are your
thoughts?
SOLID
Interface
Segregation
Principle
Interface
Segregation
Principle
No client should be forced to depend
on methods it does not use
Interfaces have more to do with the
classes that use them than with the
classes that implement them
Examples
Depending on not used methods
• Forces you to recompile when those methods change
• Forces you to redeploy
Depending on not used methods
• Makes it harder to understand
Depending on not used methods
• Makes it harder to reuse
• Forces you to have empty mehods
What are your
thoughts?
SOLID
Dependency
Inversion
Principle
Dependency
Inversion
Principle
High-level modules should not depend
on low-level modules. Both should
depend on abstractions.
Abstractions should not depend on
details. Details should depend on
abstractions.
Dependency Injection
Inversion of control
Dependency
Inversion
Principle
High-level modules should not depend
on low-level modules. Both should
depend on abstractions.
Abstractions should not depend on
details. Details should depend on
abstractions.
Dependency Inversion
Dependency
Inversion
Principle
Should we abstract
everything?
SOLID
Should we make a milion
tiny classes?
https://www.youtube.com/watch?v=llGgO74uXMI
Core Design Principles for Software Developers by Venkat
Subramaniam
4 rules of simple design
• Passes the tests
• Reveals intention
• No duplication
• Fewest elements
TRUE
• Transparent: The consequence of change should be obvious in the
code that is changing and in distant code that relies upon it
• Reasonable: The cost of any change should be proportional to the
benefits the change achieves
• Usable: The code should be usable in new and unexpected contexs
• Exemplary: The code itself should encourage those that use it to
perpetuate those qualities
Thank you!
Now questions! and more thoughts?
@alfredodev
afernandez@plainconcepts.com

More Related Content

Similar to Solid

Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 

Similar to Solid (20)

Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designs
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
SOLID in PHP
SOLID in PHPSOLID in PHP
SOLID in PHP
 
The 360 Developer
The 360 DeveloperThe 360 Developer
The 360 Developer
 
Rediscovering Modularity
Rediscovering ModularityRediscovering Modularity
Rediscovering Modularity
 
Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examples
 
Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and Manners
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Evgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shapeEvgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shape
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Talking to your organization about Elixir
Talking to your organization about ElixirTalking to your organization about Elixir
Talking to your organization about Elixir
 
Clean code
Clean codeClean code
Clean code
 
2CPP19 - Summation
2CPP19 - Summation2CPP19 - Summation
2CPP19 - Summation
 
Generic or specific? Making sensible software design decisions
 Generic or specific? Making sensible software design decisions  Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 

More from Alfredo Fernández López (8)

Cqs v2
Cqs v2Cqs v2
Cqs v2
 
CQS
CQSCQS
CQS
 
Webdriver
WebdriverWebdriver
Webdriver
 
Introducción a Angularjs
Introducción a AngularjsIntroducción a Angularjs
Introducción a Angularjs
 
Desarrollo de aplicaciones web con asp.net mvc
Desarrollo de aplicaciones web con asp.net mvcDesarrollo de aplicaciones web con asp.net mvc
Desarrollo de aplicaciones web con asp.net mvc
 
Desarrollo de aplicaciones spa (single page application) con angular.js
Desarrollo de aplicaciones spa (single page application) con angular.jsDesarrollo de aplicaciones spa (single page application) con angular.js
Desarrollo de aplicaciones spa (single page application) con angular.js
 
Web que
Web queWeb que
Web que
 
Construyendo tu ecosistema de desarrollo web
Construyendo tu ecosistema de desarrollo webConstruyendo tu ecosistema de desarrollo web
Construyendo tu ecosistema de desarrollo web
 

Recently uploaded

Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 

Solid