SlideShare une entreprise Scribd logo
1  sur  15
SOLID
The Open/Closed Principle
Dependency Inversion
Paul Blundell
@Blundell_apps
www.blundellapps.com
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likely that a
programmer will create a system that is easy to maintain and extend
over time”
S ?
O ?
L ?
I ?
D ?
SOLID
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likely that a
programmer will create a system that is easy to maintain and extend
over time”
Single Responsibility Principle
Open / Closed Principle
Liskov’s Substitution
Interface Segregation
Dependency Inversion
SOLID
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likely that a
programmer will create a system that is easy to maintain and extend
over time”
Single Responsibility Principle
Open / Closed Principle
Liskov’s Substitution
Interface Segregation
Dependency Inversion
SOLID
Open / Closed Principle
?
SOLID
Open / Closed Principle
“Software entities (classes, modules,
methods etc) should be open for extension
but closed for modification”
That is such an entity can allow its behaviour
to be changed without altering its source
code.
SOLID
Open Closed Principle
Open Closed Principle
Dependency Inversion
The aim of the OCP kata is to use the Open
Closed Principle to design a maintainable
and extensible code base.
Think about:
- How to compose functionality out of existing
objects
- How to avoid reworking existing code
OCP Kata
Write the first failing test
Then write a factory that returns an object or
a composed object that makes the test
pass.
Rules:
- the factory should be limited to creating and
linking objects
- no conditionals allowed in the factory
OCP Kata
@Test
public void scoreZeroForGutterGame() {
// First test
}
@Test
public void scoreTwentyForAllOnesGame() {
// Second test
}
// Continue
Bowling OCP Kata
Write the next failing test
Can you make this test pass by just changing
the factory and object composite?
Yes - Great do it!
No - Refactor until you can
The refactoring should be the system to a state where it’s possible to
implement the next test just by changing the composite of objects that
is returned by the factory. Do not implement new functionality when
refactoring the current test must still fail.
OCP Kata
Fork / Clone this repo:
git@github.com:novoda/dojos.git
Goto this folder:
github.com/novoda/dojos/tree/master/ocpBowling
Make a copy of this folder (rename default with a team name):
github.com/novoda/dojos/tree/master/ocpBowling/20130918-default
Rules are in the repo here:
ocpBowling/20130918-default/src/main/java/com/bowling/bowling_rules.txt
Start!
OCP Kata
Matteo Vaccari
- invented the OCP Kata
- http://matteo.vaccari.name/blog/archives/293
David Nicolette
- created the OCP jigsaw diagram
Uncle Bob
- Creator of the original bowling Kata
- http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata
Kevin Rutherford
- guided me in the art of Kata’s
- http://silkandspinach.net/
Jonas Gauffin
- for the meme
- http://blog.gauffin.org/2012/05/solid-principles-with-real-world-examples/#.UjWDy9K_s2k
Credits
Paul Blundell
@Blundell_apps
www.blundellapps.com

Contenu connexe

Tendances

A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
maheshm1206
 

Tendances (20)

Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
The history of selenium
The history of seleniumThe history of selenium
The history of selenium
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Refactoring Techniques
Refactoring TechniquesRefactoring Techniques
Refactoring Techniques
 
Retrofit
RetrofitRetrofit
Retrofit
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Solid principles
Solid principlesSolid principles
Solid principles
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
 

En vedette

"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
Serhiy Oplakanets
 
Solid principles
Solid principlesSolid principles
Solid principles
Viet Vu
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
Sam Hennessy
 
Panduan microsoft word_20071
Panduan microsoft word_20071Panduan microsoft word_20071
Panduan microsoft word_20071
Amri Abdillah
 
Roditelskoe sobranie 11klassy
Roditelskoe sobranie 11klassyRoditelskoe sobranie 11klassy
Roditelskoe sobranie 11klassy
lili4ka54
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
widhiyani
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
widhiyani
 

En vedette (20)

Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented DesignSOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
 
The Open Closed Principle - Part 1 - The Original Version
The Open Closed Principle - Part 1 - The Original VersionThe Open Closed Principle - Part 1 - The Original Version
The Open Closed Principle - Part 1 - The Original Version
 
The Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary VersionThe Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary Version
 
OCP kata overview
OCP kata overviewOCP kata overview
OCP kata overview
 
Kata rules
Kata rulesKata rules
Kata rules
 
SOLID refactoring - racing car katas
SOLID refactoring - racing car katasSOLID refactoring - racing car katas
SOLID refactoring - racing car katas
 
Smolen Alex Securing The Mvc Architecture Part Two
Smolen Alex Securing The Mvc Architecture Part TwoSmolen Alex Securing The Mvc Architecture Part Two
Smolen Alex Securing The Mvc Architecture Part Two
 
Solid principles
Solid principlesSolid principles
Solid principles
 
jeas_0816_4883
jeas_0816_4883jeas_0816_4883
jeas_0816_4883
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
 
Panduan microsoft word_20071
Panduan microsoft word_20071Panduan microsoft word_20071
Panduan microsoft word_20071
 
Entrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspectiveEntrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspective
 
Roditelskoe sobranie 11klassy
Roditelskoe sobranie 11klassyRoditelskoe sobranie 11klassy
Roditelskoe sobranie 11klassy
 
Open house2
Open house2Open house2
Open house2
 
Justice ,justice shall you pursue
Justice ,justice shall you pursueJustice ,justice shall you pursue
Justice ,justice shall you pursue
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
 

Similaire à Open Closed Principle kata

Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
WO Community
 

Similaire à Open Closed Principle kata (20)

Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Solid principle
Solid principleSolid principle
Solid principle
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
11th Salesforce Developer Group meeting in Bilbao
11th Salesforce Developer Group meeting in Bilbao11th Salesforce Developer Group meeting in Bilbao
11th Salesforce Developer Group meeting in Bilbao
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Design for Testability
Design for TestabilityDesign for Testability
Design for Testability
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Come si applica l'OCP
Come si applica l'OCPCome si applica l'OCP
Come si applica l'OCP
 
L2624 labriola
L2624 labriolaL2624 labriola
L2624 labriola
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 
Ansible top 10 - 2018
Ansible top 10 -  2018Ansible top 10 -  2018
Ansible top 10 - 2018
 
Common design principles and design patterns in automation testing
Common design principles and design patterns in automation testingCommon design principles and design patterns in automation testing
Common design principles and design patterns in automation testing
 
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
 
OpenDaylight Developers Experience 1.5: Eclipse Setup, HOT reload, future plans
OpenDaylight Developers Experience 1.5: Eclipse Setup, HOT reload, future plansOpenDaylight Developers Experience 1.5: Eclipse Setup, HOT reload, future plans
OpenDaylight Developers Experience 1.5: Eclipse Setup, HOT reload, future plans
 
The software design principles
The software design principlesThe software design principles
The software design principles
 
Solid
SolidSolid
Solid
 

Plus de Paul Blundell

Plus de Paul Blundell (16)

In 10 mins a software crafting journey
In 10 mins a software crafting journeyIn 10 mins a software crafting journey
In 10 mins a software crafting journey
 
The Novoda Craft University
The Novoda Craft UniversityThe Novoda Craft University
The Novoda Craft University
 
Android Things - Solid Foundations
Android Things - Solid FoundationsAndroid Things - Solid Foundations
Android Things - Solid Foundations
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussions
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
 
Survival of the Continuist
Survival of the ContinuistSurvival of the Continuist
Survival of the Continuist
 
Google I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech AnnouncementsGoogle I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech Announcements
 
Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6 Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6
 
Android Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cAndroid Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4c
 
Android Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4bAndroid Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4b
 
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4aAndroid Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
 
Y U NO CRAFTSMAN
Y U NO CRAFTSMANY U NO CRAFTSMAN
Y U NO CRAFTSMAN
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to Mutation
 
Jenkins project based authorization
Jenkins   project based authorizationJenkins   project based authorization
Jenkins project based authorization
 
Judge my gym - GymBabes Walkthrough
Judge my gym - GymBabes WalkthroughJudge my gym - GymBabes Walkthrough
Judge my gym - GymBabes Walkthrough
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 
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
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

Open Closed Principle kata

  • 1. SOLID The Open/Closed Principle Dependency Inversion Paul Blundell @Blundell_apps www.blundellapps.com
  • 2. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” S ? O ? L ? I ? D ? SOLID
  • 3. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” Single Responsibility Principle Open / Closed Principle Liskov’s Substitution Interface Segregation Dependency Inversion SOLID
  • 4. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” Single Responsibility Principle Open / Closed Principle Liskov’s Substitution Interface Segregation Dependency Inversion SOLID
  • 5. Open / Closed Principle ? SOLID
  • 6. Open / Closed Principle “Software entities (classes, modules, methods etc) should be open for extension but closed for modification” That is such an entity can allow its behaviour to be changed without altering its source code. SOLID
  • 10. The aim of the OCP kata is to use the Open Closed Principle to design a maintainable and extensible code base. Think about: - How to compose functionality out of existing objects - How to avoid reworking existing code OCP Kata
  • 11. Write the first failing test Then write a factory that returns an object or a composed object that makes the test pass. Rules: - the factory should be limited to creating and linking objects - no conditionals allowed in the factory OCP Kata
  • 12. @Test public void scoreZeroForGutterGame() { // First test } @Test public void scoreTwentyForAllOnesGame() { // Second test } // Continue Bowling OCP Kata
  • 13. Write the next failing test Can you make this test pass by just changing the factory and object composite? Yes - Great do it! No - Refactor until you can The refactoring should be the system to a state where it’s possible to implement the next test just by changing the composite of objects that is returned by the factory. Do not implement new functionality when refactoring the current test must still fail. OCP Kata
  • 14. Fork / Clone this repo: git@github.com:novoda/dojos.git Goto this folder: github.com/novoda/dojos/tree/master/ocpBowling Make a copy of this folder (rename default with a team name): github.com/novoda/dojos/tree/master/ocpBowling/20130918-default Rules are in the repo here: ocpBowling/20130918-default/src/main/java/com/bowling/bowling_rules.txt Start! OCP Kata
  • 15. Matteo Vaccari - invented the OCP Kata - http://matteo.vaccari.name/blog/archives/293 David Nicolette - created the OCP jigsaw diagram Uncle Bob - Creator of the original bowling Kata - http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata Kevin Rutherford - guided me in the art of Kata’s - http://silkandspinach.net/ Jonas Gauffin - for the meme - http://blog.gauffin.org/2012/05/solid-principles-with-real-world-examples/#.UjWDy9K_s2k Credits Paul Blundell @Blundell_apps www.blundellapps.com