SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Similar a 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 a 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
 

Más de 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
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
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
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 

Solid