SlideShare a Scribd company logo
4
Most read
6
Most read
7
Most read
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

More Related Content

PDF
GitOps and ArgoCD
PPT
SOLID Design Principles
PPTX
SOLID Principles
PPTX
Single Responsibility Principle
PDF
Real Life Clean Architecture
PPTX
SOLID principles
PDF
Terraform -- Infrastructure as Code
PDF
Hands-On Introduction to Kubernetes at LISA17
GitOps and ArgoCD
SOLID Design Principles
SOLID Principles
Single Responsibility Principle
Real Life Clean Architecture
SOLID principles
Terraform -- Infrastructure as Code
Hands-On Introduction to Kubernetes at LISA17

What's hot (20)

PPTX
Learning solid principles using c#
PPTX
Design principles - SOLID
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
KEY
Solid principles
PDF
Introduction to Kubernetes Workshop
PDF
OpenShift 4, the smarter Kubernetes platform
PPTX
Docker: From Zero to Hero
PPTX
Spring Cloud Config
PPTX
Introduction to docker
PDF
Clean Architecture
PDF
Kubernetes
PPTX
PDF
JPA and Hibernate
PDF
ODP
Introduction to Version Control
PDF
Introduction to docker
PPTX
Introduction to microservices
PPTX
Git commands
PDF
GitOps with ArgoCD
PPTX
A Practical Guide to Domain Driven Design: Presentation Slides
Learning solid principles using c#
Design principles - SOLID
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Solid principles
Introduction to Kubernetes Workshop
OpenShift 4, the smarter Kubernetes platform
Docker: From Zero to Hero
Spring Cloud Config
Introduction to docker
Clean Architecture
Kubernetes
JPA and Hibernate
Introduction to Version Control
Introduction to docker
Introduction to microservices
Git commands
GitOps with ArgoCD
A Practical Guide to Domain Driven Design: Presentation Slides
Ad

Viewers also liked (20)

PPTX
Object Oriented Design SOLID Principles
PPTX
SOLID Principles part 1
KEY
"SOLID" Object Oriented Design Principles
PPTX
SOLID - Principles of Object Oriented Design
PDF
The Open Closed Principle - Part 1 - The Original Version
PDF
The Open-Closed Principle - the Original Version and the Contemporary Version
ODP
OCP kata overview
ODP
Kata rules
ODP
SOLID refactoring - racing car katas
PPT
Smolen Alex Securing The Mvc Architecture Part Two
ODP
Open Close Principle
PPTX
Solid principles
PDF
jeas_0816_4883
PPTX
Dependency Inversion Principle
PPTX
Implementing The Open/Closed Principle
PDF
Panduan microsoft word_20071
PPT
Entrepreneurship from a regional market perspective
PPT
Roditelskoe sobranie 11klassy
PPTX
Open house2
PPT
Justice ,justice shall you pursue
Object Oriented Design SOLID Principles
SOLID Principles part 1
"SOLID" Object Oriented Design Principles
SOLID - Principles of Object Oriented Design
The Open Closed Principle - Part 1 - The Original Version
The Open-Closed Principle - the Original Version and the Contemporary Version
OCP kata overview
Kata rules
SOLID refactoring - racing car katas
Smolen Alex Securing The Mvc Architecture Part Two
Open Close Principle
Solid principles
jeas_0816_4883
Dependency Inversion Principle
Implementing The Open/Closed Principle
Panduan microsoft word_20071
Entrepreneurship from a regional market perspective
Roditelskoe sobranie 11klassy
Open house2
Justice ,justice shall you pursue
Ad

Similar to Open Closed Principle kata (20)

PDF
Come si applica l'OCP
PPTX
1012892161-Module-4-Agile-Software-Design-and-Development.pptx
PPTX
Solid design principles
PDF
Solid principle
PDF
SOLID Design Principles for Test Automaion
PPTX
Improving the Design of Existing Software
PPTX
SOLID_Principles_Explained_Presentation.pptx
PDF
Solid principes
PPTX
Improving the Quality of Existing Software
PDF
SOLID Principles, Building reusable, maintainable, scalable and testable soft...
PDF
Twins: OOP and FP
PPTX
Improving the Quality of Existing Software
PPTX
INTRODUCTION TO JAVA
PPTX
Improving the Quality of Existing Software
PDF
TWINS: OOP and FP - Warburton
PPTX
Improving the Quality of Existing Software - DevIntersection April 2016
PPT
DesignPrinciples-and-DesignPatterns
PPTX
Solid as OOP abstraction
PPTX
SOLID Principles of Refactoring Presentation - Inland Empire User Group
Come si applica l'OCP
1012892161-Module-4-Agile-Software-Design-and-Development.pptx
Solid design principles
Solid principle
SOLID Design Principles for Test Automaion
Improving the Design of Existing Software
SOLID_Principles_Explained_Presentation.pptx
Solid principes
Improving the Quality of Existing Software
SOLID Principles, Building reusable, maintainable, scalable and testable soft...
Twins: OOP and FP
Improving the Quality of Existing Software
INTRODUCTION TO JAVA
Improving the Quality of Existing Software
TWINS: OOP and FP - Warburton
Improving the Quality of Existing Software - DevIntersection April 2016
DesignPrinciples-and-DesignPatterns
Solid as OOP abstraction
SOLID Principles of Refactoring Presentation - Inland Empire User Group

More from Paul Blundell (16)

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

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Monthly Chronicles - July 2025
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.

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