SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Softwerkskammer - Coding Dojo
Racing Car Katas
S.O.L.I.D & Refactoring
https://www.slideshare.net/georgberky/solid-refactoring-racing-car-katas
let’s practice together
● all professionals practice
● how about us programmers?
● when was the last time you sat down to really
understand a problem?
● tonight we have time to do that
the ground rules
● write tests
● work together in pairs
● write down
– �: what did you learn
– �: what made you lose focus
– �: what confused you
– � : what annoyed you
● share with everybody
● be excellent to each other
the ground rules
● if you have the keyboard, you get to decide what to type
● if you have the keyboard and you don’t know what to
type, ask for help
● if you are asked for help, kindly respond to the best of
your ability
● if you are not asked, but you see an opportunity for
improvement or learning, choose an appropriate
moment to mention it like the next green test or the
retrospective
from: Emily Bache – The Coding Dojo Handbook
the exercise
● choose one exercise
● add tests for the class
– Leaderboard: add tests using SelfDrivingCar
● write down where SOLID principles were violated
● repeat
● share with your fellow craftspeople
SOLID
● Single responsibility principle (SRP)
● Open/closed principle (OCP)
● Liskov substitution principle (LSP)
● Interface segregation principle (ISP)
● Dependency inversion principle (DIP)
single responsibility principle
● responsibility = reason to change
● if nothing ever changed: no problem
● change is the fundamental reality of our
business
SRP - ExpensesReport
● store/retrieve expenses:
– Excel, CSV, database
– cause: infrastructure
● compile report from expenses
– taxes, sorting
– cause: business rules
● format and print report
– plain text, HTML
– cause: cosmetic
open/closed principle
● open for extension, closed for modification
● huh? ��♂�‍ ️
● when facing change: introduce abstractions
● abstraction = interface (see DIP)
● we need to open/close our design
● this is a voluntary choice
● driven by the fact/requirement of change
● avoid BDUF, practice refactoring
OCP - FizzBuzz
● add one if per number: �
● possible abstractions:
– NumberSayer (immediate choice)
– NumberStrategy (higher abstraction)
● open: extending behavior by adding interface
implementation
● closed: original code does not change when adding a
new number
● cf.: Craig Larman – Protected Variation
Liskov substitution principle
● polymorphism must be transparent to clients
● the client must not care which implementation is used
● instanceof is a smell: broken abstraction
● all contracts of superclass must be kept:
– preconditions
– postconditions
– invariants
– history constraint
LSP - square/rectangle
● class Square extends Rectangle ?
● change width of square
● height has to change too
● contract of Rectangle:
postcondition: setWidth(n) getWidth ()== n⇒
● contract of Square:
invariant: height == width
LSP - square/rectangle
● you cannot drop in a square for a rectangle
● unit tests help you see these contracts
● try to use the same test for subclasses!
● OOP inheritance does not have to follow real
live inheritance
● cf.: design by contract
interface segregation principle
● do not depend on more than you need
● keep your interfaces slim
● extract interface from dependency if you only
use some of the methods
ISP – primitive obsession
● use first class collections:
– do you need all 32 public methods of java.util.List ?
– clarity: Calendar instead of List<Appointment>
● use value types
– DeviceId instead of String
– 76 exposed methods of String
ISP – service locator
● <T> ServiceLocator.getService(Class<T> class)
● infinite number of methods
● ServiceLocator.getService(String.class)
● invisible preconditions:
– serviceClass needs to be in directory
– only discovered at runtime
● constructor:
– explicit precondition
– discovered at compile time
dependency inversion principle
● do not depend on low level details
● depend on high level abstractions instead
● business rules (high level) should not change
when implementation details (low level) change
● e.g. report calculation has to change when data
storage changes?
DIP – button/light
● class Button
– void toggle()
● class LightBulb
– void turnOn()
– void turnOff()
● change: button should work with TV
● class TV
– void powerOn()
– void powerOff()
DIP – button/light
● option 1:
– public Button(LightBulb lightBulb)
– public Button(TV tv)
– void toggle():
● if(lightBulb != null && tv == null) { … }
● if(tv != null && lightBulb == null) { … }
– now add five more classes: �
DIP – button/light
● option 2:
– interface Switchable
● void turnOn()
● void turnOff()
– class LightBulb implements Switchable
– class TV implements Switchable
– public Button(Switchable switchable)
– void toggle(): straightforward
DIP – button/light
● client: Button
– depends on high level abstraction
– “something that can be switched on and off”
– interface, abstract class, multimethod
● low level details:
– turnOn/powerOn, turnOff/powerOff
– depend on abstraction too
– by implementing it
● no dependency on low level details
● interface “owned” by the client
the exercise
● racing car katas
● by Emily Bache & Luca Minudel
● git clone
https://github.com/emilybache/Racing-Car-Katas.git

Weitere ähnliche Inhalte

Was ist angesagt?

Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipTheo Jungeblut
 
Escalonamento em 3 níveis e Escalonamento por alternância circular
Escalonamento em 3 níveis e Escalonamento por alternância circularEscalonamento em 3 níveis e Escalonamento por alternância circular
Escalonamento em 3 níveis e Escalonamento por alternância circularEmmanuel Saes
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and PracticesAnand Bagmar
 
Fcfs scheduling
Fcfs schedulingFcfs scheduling
Fcfs schedulingmyrajendra
 
Head First Java Chapter 1
Head First Java Chapter 1Head First Java Chapter 1
Head First Java Chapter 1Tom Henricksen
 
Patterns of a “good” test automation framework
Patterns of a “good” test automation frameworkPatterns of a “good” test automation framework
Patterns of a “good” test automation frameworkAnand Bagmar
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handlingRohitK71
 
Evolution of Applications & Web
Evolution of Applications & WebEvolution of Applications & Web
Evolution of Applications & WebHimanshu Jindal
 

Was ist angesagt? (10)

Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
Escalonamento em 3 níveis e Escalonamento por alternância circular
Escalonamento em 3 níveis e Escalonamento por alternância circularEscalonamento em 3 níveis e Escalonamento por alternância circular
Escalonamento em 3 níveis e Escalonamento por alternância circular
 
Clean code
Clean codeClean code
Clean code
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
Fcfs scheduling
Fcfs schedulingFcfs scheduling
Fcfs scheduling
 
Head First Java Chapter 1
Head First Java Chapter 1Head First Java Chapter 1
Head First Java Chapter 1
 
Patterns of a “good” test automation framework
Patterns of a “good” test automation frameworkPatterns of a “good” test automation framework
Patterns of a “good” test automation framework
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
 
Gemba Walk 201
Gemba Walk 201Gemba Walk 201
Gemba Walk 201
 
Evolution of Applications & Web
Evolution of Applications & WebEvolution of Applications & Web
Evolution of Applications & Web
 

Ähnlich wie Coding Dojo Focuses on SOLID Principles

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
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
 
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
 
OutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems
 
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...MysoreMuleSoftMeetup
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCefalo
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8John Godoi
 
Software Engineering Primer
Software Engineering PrimerSoftware Engineering Primer
Software Engineering PrimerGeorg Buske
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
Lecture01 algorithm analysis
Lecture01 algorithm analysisLecture01 algorithm analysis
Lecture01 algorithm analysisZara Nawaz
 
Validating big data jobs - Spark AI Summit EU
Validating big data jobs  - Spark AI Summit EUValidating big data jobs  - Spark AI Summit EU
Validating big data jobs - Spark AI Summit EUHolden Karau
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...Databricks
 
The benefit of sneezing code into an editor vs clean code
The benefit of sneezing code into an editor vs clean codeThe benefit of sneezing code into an editor vs clean code
The benefit of sneezing code into an editor vs clean codeDave Hulbert
 
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...VMware Tanzu
 
[SRD UGM] Sharing Session - Software Testing
[SRD UGM] Sharing Session - Software Testing[SRD UGM] Sharing Session - Software Testing
[SRD UGM] Sharing Session - Software TestingAhmad Widardi
 
Production-Ready BIG ML Workflows - from zero to hero
Production-Ready BIG ML Workflows - from zero to heroProduction-Ready BIG ML Workflows - from zero to hero
Production-Ready BIG ML Workflows - from zero to heroDaniel Marcous
 

Ähnlich wie Coding Dojo Focuses on SOLID Principles (20)

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
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
 
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
 
OutSystems Tips and Tricks
OutSystems Tips and TricksOutSystems Tips and Tricks
OutSystems Tips and Tricks
 
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...
Log4j2 - A deep dive into the logging services in Mulesoft with On-Prem deplo...
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8
 
Software Engineering Primer
Software Engineering PrimerSoftware Engineering Primer
Software Engineering Primer
 
Rails data migrations
Rails data migrationsRails data migrations
Rails data migrations
 
Better java with design
Better java with designBetter java with design
Better java with design
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
API Design
API DesignAPI Design
API Design
 
Lecture01 algorithm analysis
Lecture01 algorithm analysisLecture01 algorithm analysis
Lecture01 algorithm analysis
 
Validating big data jobs - Spark AI Summit EU
Validating big data jobs  - Spark AI Summit EUValidating big data jobs  - Spark AI Summit EU
Validating big data jobs - Spark AI Summit EU
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 
Evolve with laravel
Evolve with laravelEvolve with laravel
Evolve with laravel
 
The benefit of sneezing code into an editor vs clean code
The benefit of sneezing code into an editor vs clean codeThe benefit of sneezing code into an editor vs clean code
The benefit of sneezing code into an editor vs clean code
 
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
 
[SRD UGM] Sharing Session - Software Testing
[SRD UGM] Sharing Session - Software Testing[SRD UGM] Sharing Session - Software Testing
[SRD UGM] Sharing Session - Software Testing
 
Production-Ready BIG ML Workflows - from zero to hero
Production-Ready BIG ML Workflows - from zero to heroProduction-Ready BIG ML Workflows - from zero to hero
Production-Ready BIG ML Workflows - from zero to hero
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Coding Dojo Focuses on SOLID Principles

  • 1. Softwerkskammer - Coding Dojo Racing Car Katas S.O.L.I.D & Refactoring
  • 3. let’s practice together ● all professionals practice ● how about us programmers? ● when was the last time you sat down to really understand a problem? ● tonight we have time to do that
  • 4. the ground rules ● write tests ● work together in pairs ● write down – �: what did you learn – �: what made you lose focus – �: what confused you – � : what annoyed you ● share with everybody ● be excellent to each other
  • 5. the ground rules ● if you have the keyboard, you get to decide what to type ● if you have the keyboard and you don’t know what to type, ask for help ● if you are asked for help, kindly respond to the best of your ability ● if you are not asked, but you see an opportunity for improvement or learning, choose an appropriate moment to mention it like the next green test or the retrospective from: Emily Bache – The Coding Dojo Handbook
  • 6. the exercise ● choose one exercise ● add tests for the class – Leaderboard: add tests using SelfDrivingCar ● write down where SOLID principles were violated ● repeat ● share with your fellow craftspeople
  • 7. SOLID ● Single responsibility principle (SRP) ● Open/closed principle (OCP) ● Liskov substitution principle (LSP) ● Interface segregation principle (ISP) ● Dependency inversion principle (DIP)
  • 8. single responsibility principle ● responsibility = reason to change ● if nothing ever changed: no problem ● change is the fundamental reality of our business
  • 9. SRP - ExpensesReport ● store/retrieve expenses: – Excel, CSV, database – cause: infrastructure ● compile report from expenses – taxes, sorting – cause: business rules ● format and print report – plain text, HTML – cause: cosmetic
  • 10. open/closed principle ● open for extension, closed for modification ● huh? ��♂�‍ ️ ● when facing change: introduce abstractions ● abstraction = interface (see DIP) ● we need to open/close our design ● this is a voluntary choice ● driven by the fact/requirement of change ● avoid BDUF, practice refactoring
  • 11. OCP - FizzBuzz ● add one if per number: � ● possible abstractions: – NumberSayer (immediate choice) – NumberStrategy (higher abstraction) ● open: extending behavior by adding interface implementation ● closed: original code does not change when adding a new number ● cf.: Craig Larman – Protected Variation
  • 12. Liskov substitution principle ● polymorphism must be transparent to clients ● the client must not care which implementation is used ● instanceof is a smell: broken abstraction ● all contracts of superclass must be kept: – preconditions – postconditions – invariants – history constraint
  • 13. LSP - square/rectangle ● class Square extends Rectangle ? ● change width of square ● height has to change too ● contract of Rectangle: postcondition: setWidth(n) getWidth ()== n⇒ ● contract of Square: invariant: height == width
  • 14. LSP - square/rectangle ● you cannot drop in a square for a rectangle ● unit tests help you see these contracts ● try to use the same test for subclasses! ● OOP inheritance does not have to follow real live inheritance ● cf.: design by contract
  • 15. interface segregation principle ● do not depend on more than you need ● keep your interfaces slim ● extract interface from dependency if you only use some of the methods
  • 16. ISP – primitive obsession ● use first class collections: – do you need all 32 public methods of java.util.List ? – clarity: Calendar instead of List<Appointment> ● use value types – DeviceId instead of String – 76 exposed methods of String
  • 17. ISP – service locator ● <T> ServiceLocator.getService(Class<T> class) ● infinite number of methods ● ServiceLocator.getService(String.class) ● invisible preconditions: – serviceClass needs to be in directory – only discovered at runtime ● constructor: – explicit precondition – discovered at compile time
  • 18. dependency inversion principle ● do not depend on low level details ● depend on high level abstractions instead ● business rules (high level) should not change when implementation details (low level) change ● e.g. report calculation has to change when data storage changes?
  • 19. DIP – button/light ● class Button – void toggle() ● class LightBulb – void turnOn() – void turnOff() ● change: button should work with TV ● class TV – void powerOn() – void powerOff()
  • 20. DIP – button/light ● option 1: – public Button(LightBulb lightBulb) – public Button(TV tv) – void toggle(): ● if(lightBulb != null && tv == null) { … } ● if(tv != null && lightBulb == null) { … } – now add five more classes: �
  • 21. DIP – button/light ● option 2: – interface Switchable ● void turnOn() ● void turnOff() – class LightBulb implements Switchable – class TV implements Switchable – public Button(Switchable switchable) – void toggle(): straightforward
  • 22. DIP – button/light ● client: Button – depends on high level abstraction – “something that can be switched on and off” – interface, abstract class, multimethod ● low level details: – turnOn/powerOn, turnOff/powerOff – depend on abstraction too – by implementing it ● no dependency on low level details ● interface “owned” by the client
  • 23. the exercise ● racing car katas ● by Emily Bache & Luca Minudel ● git clone https://github.com/emilybache/Racing-Car-Katas.git