SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Maksym Husar
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesBruno Bossola
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideVictor Rentea
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID PrinciplesGanesh Samarthyam
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#Aditya Kumar Rajan
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfVictor Rentea
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSergey Karpushin
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsRicardo Wilkins
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principlemuhammadali0014
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithVictor Rentea
 

What's hot (20)

Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design Principles
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdf
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
 
Clean code
Clean codeClean code
Clean code
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principle
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 

Similar to 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
 
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
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design PrinciplesSerhiy Oplakanets
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesDr. Syed Hassan Amin
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 

Similar to 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
 
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
 
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
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Clean code
Clean codeClean code
Clean code
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
🐬 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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
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, ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

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

Editor's Notes

  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.