SlideShare une entreprise Scribd logo
1  sur  47
Becoming a better developer by using
the SOLID design principles
How to write code that’s easy to maintain, extend and understand
Katerina
Trajchevska
● Senior Software Engineer & co-
founder of Adeva
● Remote Work Advocate
● Community Volunteer
● Consultant with startups and
Fortune 500 companies
Software Engineer and co-
founder of Adeva
@ktrajchevska
Working on legacy code
● Re-reading code multiple times to get to the part you need to change
● Hard to understand what a method does
● Spending a lot of time to fix a minor bug
● You spend more time reading than writing code.
@ktrajchevska
Working on a startup product
● In charge of the development process
● Constantly adding new features
● No formal process
● Very dynamic environment, no time to worry about code structure
● What is it like to go back to your code after 2 years?
@ktrajchevska
What will we talk about today?
● What is SOLID and how it can make our lives easier
● What’s the purpose of each of the SOLID design principles
● How to not use SOLID
@ktrajchevska
The purpose of SOLID design principles
● To make the code more maintainable.
● To make it easier to quickly extend the system with new functionality without
breaking the existing ones.
● To make the code easier to read and understand, thus spend less time figuring
out what it does and more time actually developing the solution.
● Introduced by Robert Martin (Uncle Bob), named by Michael Feathers.
Single Responsibility
Principle
A class should have one, and only one, reason to change.
@ktrajchevska
Single Responsibility Principle
● A class should only be responsible for one thing.
● There’s a place for everything and everything is in its place.
● Find one reason to change and take everything else out of the class.
● Very precise names for many small classes > generic names for large classes.
Open/Closed Principle
An entity should be open for extension, but closed for
modification.
@ktrajchevska
Open/Closed Principle
● An entity should be open for extension but closed for modification.
● Extend functionality by adding new code instead of changing existing code.
● Separate the behaviors, so the system can easily be extended, but never
broken.
● Goal: get to a point where you can never break the core of your system.
Liskov Substitution Principle
Let φ(x) be a property provable about objects x of type T.
Then φ(y) should be true for objects y of type S where S is
a subtype of T.
@ktrajchevska
Liskov Substitution Principle
● Any derived class should be able to substitute its parent class without the
consumer knowing it.
● Every class that implements an interface, must be able to substitute any
reference throughout the code that implements that same interface.
● Every part of the code should get the expected result no matter what instance
of a class you send to it, given it implements the same interface.
Image credits: Derick Bailey
Interface Segregation
Principle
No client should be forced to depend on methods it does
not use.
@ktrajchevska
Interface Segregation Principle
● A client should never be forced to depend on methods it doesn't use.
● Or, a client should never depend on anything more than the method it’s calling.
● Changing one method in a class shouldn’t affect classes that don’t depend on
it.
● Replace fat interfaces with many small, specific interfaces.
Dependency Inversion
Principle
High-level modules should not depend on low-level
modules. Both should depend on abstractions.
Image credits: Derick Bailey
@ktrajchevska
Dependency Inversion Principle
● Never depend on anything concrete, only depend on abstractions.
● High level modules should not depend on low level modules. They should
depend on abstractions.
● Able to change an implementation easily without altering the high level code.
@ktrajchevska
⚠️ Don’t get trapped by SOLID
● SOLID design principles are principles, not rules.
● Always use common sense when applying SOLID.
● Avoid over-fragmenting your code for the sake of SRP or SOLID.
● Don’t try to achieve SOLID, use SOLID to achieve maintainability.
@ktrajchevska
Final Thoughts
● The purpose of SOLID principles is to make your code more maintainable, easy
to extend and reason about.
● It requires spending more time writing code, so you can spend less reading it
later.
● SOLID principles are principles, not rules.
● Always know your trade-offs and use common sense.
● SOLID is your tool, not your goal.
Thank you 🙏
@ktrajchevska
Connecting tech companies with world-class developers

Contenu connexe

Tendances

Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
OpenNebula Networking - Rubén S. Montero
OpenNebula Networking - Rubén S. MonteroOpenNebula Networking - Rubén S. Montero
OpenNebula Networking - Rubén S. MonteroOpenNebula Project
 
Airflow Best Practises & Roadmap to Airflow 2.0
Airflow Best Practises & Roadmap to Airflow 2.0Airflow Best Practises & Roadmap to Airflow 2.0
Airflow Best Practises & Roadmap to Airflow 2.0Kaxil Naik
 
Git/Gerrit with TeamForge
Git/Gerrit with TeamForgeGit/Gerrit with TeamForge
Git/Gerrit with TeamForgeCollabNet
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET CoreAvanade Nederland
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageAniruddha Chakrabarti
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVMRyan Cuprak
 
Refactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureRefactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureBrad Appleton
 
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingGCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingSimon Su
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language Mobio Solutions
 
OpenShift 4 installation
OpenShift 4 installationOpenShift 4 installation
OpenShift 4 installationRobert Bohne
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introductionJason Vance
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureMohamed Galal
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New FeaturesHaim Michael
 

Tendances (20)

Java Presentation
Java PresentationJava Presentation
Java Presentation
 
OpenNebula Networking - Rubén S. Montero
OpenNebula Networking - Rubén S. MonteroOpenNebula Networking - Rubén S. Montero
OpenNebula Networking - Rubén S. Montero
 
Airflow Best Practises & Roadmap to Airflow 2.0
Airflow Best Practises & Roadmap to Airflow 2.0Airflow Best Practises & Roadmap to Airflow 2.0
Airflow Best Practises & Roadmap to Airflow 2.0
 
Git/Gerrit with TeamForge
Git/Gerrit with TeamForgeGit/Gerrit with TeamForge
Git/Gerrit with TeamForge
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Mastering Real-time Linux
Mastering Real-time LinuxMastering Real-time Linux
Mastering Real-time Linux
 
Refactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureRefactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary Architecture
 
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic TrainingGCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
GCP - GCE, Cloud SQL, Cloud Storage, BigQuery Basic Training
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
OpenShift 4 installation
OpenShift 4 installationOpenShift 4 installation
OpenShift 4 installation
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introduction
 
Background processing with hangfire
Background processing with hangfireBackground processing with hangfire
Background processing with hangfire
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
Swoole Love PHP
Swoole Love PHPSwoole Love PHP
Swoole Love PHP
 

Similaire à Becoming a better developer by using the SOLID design principles

From good to solid: How to become a better developer
From good to solid: How to become a better developerFrom good to solid: How to become a better developer
From good to solid: How to become a better developerKaterina Trajchevska
 
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
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Maksym Husar
 
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 shapeAnna Shymchenko
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopMohammad Shawahneh
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patternsRahul Singh
 
Dependency injection using Google guice
Dependency injection using Google guiceDependency injection using Google guice
Dependency injection using Google guiceAman Verma
 
The Solid Principles
The Solid PrinciplesThe Solid Principles
The Solid PrinciplesLuke Smith
 
Refactoring workshop (Campus Party Quito 2014)
Refactoring workshop (Campus Party Quito 2014)Refactoring workshop (Campus Party Quito 2014)
Refactoring workshop (Campus Party Quito 2014)Maria Gomez
 
Is your code SOLID enough?
 Is your code SOLID enough? Is your code SOLID enough?
Is your code SOLID enough?SARCCOM
 

Similaire à Becoming a better developer by using the SOLID design principles (20)

From good to solid: How to become a better developer
From good to solid: How to become a better developerFrom good to solid: How to become a better developer
From good to solid: How to become a better developer
 
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
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
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
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Design patterns 101
Design patterns 101Design patterns 101
Design patterns 101
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Dependency injection using Google guice
Dependency injection using Google guiceDependency injection using Google guice
Dependency injection using Google guice
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Solid principles
Solid principlesSolid principles
Solid principles
 
The Solid Principles
The Solid PrinciplesThe Solid Principles
The Solid Principles
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Refactoring workshop (Campus Party Quito 2014)
Refactoring workshop (Campus Party Quito 2014)Refactoring workshop (Campus Party Quito 2014)
Refactoring workshop (Campus Party Quito 2014)
 
Is your code SOLID enough?
 Is your code SOLID enough? Is your code SOLID enough?
Is your code SOLID enough?
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 

Dernier

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Becoming a better developer by using the SOLID design principles

  • 1. Becoming a better developer by using the SOLID design principles How to write code that’s easy to maintain, extend and understand
  • 2. Katerina Trajchevska ● Senior Software Engineer & co- founder of Adeva ● Remote Work Advocate ● Community Volunteer ● Consultant with startups and Fortune 500 companies Software Engineer and co- founder of Adeva
  • 3. @ktrajchevska Working on legacy code ● Re-reading code multiple times to get to the part you need to change ● Hard to understand what a method does ● Spending a lot of time to fix a minor bug ● You spend more time reading than writing code.
  • 4.
  • 5. @ktrajchevska Working on a startup product ● In charge of the development process ● Constantly adding new features ● No formal process ● Very dynamic environment, no time to worry about code structure ● What is it like to go back to your code after 2 years?
  • 6. @ktrajchevska What will we talk about today? ● What is SOLID and how it can make our lives easier ● What’s the purpose of each of the SOLID design principles ● How to not use SOLID
  • 7. @ktrajchevska The purpose of SOLID design principles ● To make the code more maintainable. ● To make it easier to quickly extend the system with new functionality without breaking the existing ones. ● To make the code easier to read and understand, thus spend less time figuring out what it does and more time actually developing the solution. ● Introduced by Robert Martin (Uncle Bob), named by Michael Feathers.
  • 8. Single Responsibility Principle A class should have one, and only one, reason to change.
  • 9.
  • 10. @ktrajchevska Single Responsibility Principle ● A class should only be responsible for one thing. ● There’s a place for everything and everything is in its place. ● Find one reason to change and take everything else out of the class. ● Very precise names for many small classes > generic names for large classes.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Open/Closed Principle An entity should be open for extension, but closed for modification.
  • 16. @ktrajchevska Open/Closed Principle ● An entity should be open for extension but closed for modification. ● Extend functionality by adding new code instead of changing existing code. ● Separate the behaviors, so the system can easily be extended, but never broken. ● Goal: get to a point where you can never break the core of your system.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Liskov Substitution Principle Let φ(x) be a property provable about objects x of type T. Then φ(y) should be true for objects y of type S where S is a subtype of T.
  • 25. @ktrajchevska Liskov Substitution Principle ● Any derived class should be able to substitute its parent class without the consumer knowing it. ● Every class that implements an interface, must be able to substitute any reference throughout the code that implements that same interface. ● Every part of the code should get the expected result no matter what instance of a class you send to it, given it implements the same interface.
  • 27.
  • 28.
  • 29.
  • 30. Interface Segregation Principle No client should be forced to depend on methods it does not use.
  • 31.
  • 32. @ktrajchevska Interface Segregation Principle ● A client should never be forced to depend on methods it doesn't use. ● Or, a client should never depend on anything more than the method it’s calling. ● Changing one method in a class shouldn’t affect classes that don’t depend on it. ● Replace fat interfaces with many small, specific interfaces.
  • 33.
  • 34.
  • 35.
  • 36. Dependency Inversion Principle High-level modules should not depend on low-level modules. Both should depend on abstractions.
  • 38. @ktrajchevska Dependency Inversion Principle ● Never depend on anything concrete, only depend on abstractions. ● High level modules should not depend on low level modules. They should depend on abstractions. ● Able to change an implementation easily without altering the high level code.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43. @ktrajchevska ⚠️ Don’t get trapped by SOLID ● SOLID design principles are principles, not rules. ● Always use common sense when applying SOLID. ● Avoid over-fragmenting your code for the sake of SRP or SOLID. ● Don’t try to achieve SOLID, use SOLID to achieve maintainability.
  • 44.
  • 45.
  • 46. @ktrajchevska Final Thoughts ● The purpose of SOLID principles is to make your code more maintainable, easy to extend and reason about. ● It requires spending more time writing code, so you can spend less reading it later. ● SOLID principles are principles, not rules. ● Always know your trade-offs and use common sense. ● SOLID is your tool, not your goal.
  • 47. Thank you 🙏 @ktrajchevska Connecting tech companies with world-class developers

Notes de l'éditeur

  1. SRP is very similar to the concept of a clean organized room. There’s a place for everything in your room and everything should be in its place. Similarly, there should be a place for everything in your code and everything should be in its place.
  2. We can go further, by creating a mutator for the password, so the repository doesn’t need to care about what is used for password encryption.
  3. Has the most confusing name, but it could save most on development time once you understand it. A good example here is an open source library. When you install a composer package, it goes to your vendors folder and you don't touch its code - you write separate code around it that will make it compatible with your own app. After many downloads, open source libraries get tested that much that they become almost error resistant. That's your goal with OCP - to never change the core of your system, so it can get tested so much that it can never be broken.
  4. So how do we add new payment types now? Say, CouponPayment or CashOnDeliveryPayment. We simply add a new class for the new payment type, implement the pay method and tell the factory how to instantiate it. Nothing more - it should now work out of the box.
  5. Imagine this scenario, you’re working on your app and instead of creating your database structure since the beginning you use a file system just for testing purposes. Now, you have some repository that communicates with that file system - reads through the files and prepares them, so it can return the data to your program in an array format. You use it and don’t care how it’s handled in the background. That’s great. Now, you complete the development process, everything is great and now you want to replace the file system with a database. You change your repository to implement all the same methods for working with the database. But they now return a collection instead of array, which fails your program.
  6. The best way to comply to LSP in PHP right now is programing with intent.
  7. PHP, interpreted language
  8. This is a red alert! The main purpose of SOLID design principles is to make our lives easier. To make our apps more easily maintainable and extendable. If you find yourself over-fragmenting your code or doing things for the sake of the SOLID design principles that don’t actually help you maintain your app or code faster - that is a red alert
  9. OK, I know as software engineers this index.php movement probably makes you sick in the stomach :) But, it has an excellent point. Never ever overcomplicate! If you have an app that is so basic and will never need to be extended, there’s no point to over-engineer and write more code than necessary. In those cases, tying to comply with SOLID will complicate things for you instead of simplifying them. Perhaps a convenient, but not so drastic example here would be Laravel models. You can abstract the database layer with the Repository pattern and architect everything beautifully, but if it’s a simple app you’re probably better off using Eloquent models directly. SOLID requires writing more code, so you can read less. In simple apps you need to think whether it’s worth it. Again, use SOLID as a tool to make your life as a developer easier. Common sense principle is sometimes the best one to follow.