SlideShare a Scribd company logo
www.luxoft.com
SOLID Design Principles
Ionuț Bilică
What is Software Design?
SOLID Design Principles applied in Java
SOLID Design Principles applied in Java
javac
Why Is Design Important?
$$$$$
66666
$
6
javac
$
6
$$$$$
66666
Martin Fowler’s Design Stamina Hypothesis
Attention to Design
Timeneededtoimplementuserstory
User Stories
good design
no design
The primary value of software is that it is soft.
That it is resilient in the face of inevitable change.
That it not only meets the users' requirements and solves their problems in the
present tense, but that it can be readily adapted to meet needs that will arrive
tomorrow, or the next day.
The Value of Code
The Code should do its job, solving a problem that the user has today.
The secondary value of software:
SOLID
Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Design Patterns vs Design Principles
SOLID Design Principles applied in Java
SOLID Design Principles applied in Java
cleancoders.com
Single Responsibility Principle
A class should have one, and only one, reason to change.
Open Closed Principle
You should be able to extend a classes behavior, without modifying it.
Common Closure Principle
Classes that change together are packaged together.
Single Responsibility Principle
A class should have one, and only one, reason to change.
Open Closed Principle
You should be able to extend a classes behavior, without modifying it.
Common Closure Principle
Classes that change together are packaged together.
Why does software changes?
A change is requested by the product owner through a user story.
A user story relates to a business capability of the software.
A user story is written in business language.
A change comes as a user story, for a business capability, and is written in
business language.
Single Responsibility Principle
A class should have one, and only one, reason to change.
Open Closed Principle
You should be able to extend a classes behavior, without modifying it.
Common Closure Principle
Classes that change together are packaged together.
Packaging
by type by function
Packaging
by type by function
non cohesive cohesive
Package cohesion
Single Responsibility Principle
private String assemblyDirections() {
String directions = "You can go";
for (Direction to : Direction.values()) {
if (canMoveTo(to)) {
directions += " " + to;
}
}
directions += " from here.";
return directions;
}
private List<Direction> getAvailableDirections() {
List<Direction> directions = new ArrayList<>();
for (Direction to : Direction.values()) {
if (canMoveTo(to)) {
directions.add(to);
}
}
return directions;
}
private String describe(Direction[] directions) {
String str = "You can go";
for (int i=0; i<directions.length; i++) {
str += " " + directions[i];
}
str += " from here.";
return directionsStr;
}
Single Responsibility Principle
public class ResponseBuilder {
public Document buildReponseForAccept(int dealId) {
//Create service response for Accept request.
//...
}
public Document buildReponseForReject(int dealId, String reason) {
//Create service response for Reject request.
//...
}
public Document buildReponseForUpdate(int dealId, DealDiff diff) {
//Create service response for Update request.
//...
}
public Document buildResponseForWithdraw(int dealId) {
//Create service response for Update request.
//...
}
}
Single Responsibility Principle
public class Configuration {
//...
public String getHost() {
return host;
}
public int getPort() {
return port;
}
public boolean startInMaximizedWindow() {
return port;
}
public Color getMainThemeColor() {
return mainThrmeColor;
}
}
public static class ConnectionFactory {
private final String host;
private final int port;
@Inject
public ConnectionFactory(@Config String host,
@Config int port) {
this.host = host;
this.port = port;
}
//...
}
Breaking the Single Responsibility Principle
Break unrelated code
Unrelated tests fail Unrelated functionality breaks
Blame is thrown around Clients panic and build mistrust
Open Closed Principle
public void checkout(Receipt receipt) {
Money total = receipt.getTotal();
Payment p = acceptCash(total);
receipt.addPayment(p);
}
public void checkout(Receipt receipt,
PaymentMethodType paymentMethodType) {
Money total = receipt.getTotal();
Payment p = null;
if (paymentMethodType == CASH) {
p = acceptCash(total);
} else if (paymentMethodType == CREDIT) {
p = acceptCredit(total);
} else {
// There's no way to reached this. I hope.
}
receipt.addPayment(p);
}
public void checkout(Receipt receipt,
PaymentMethod paymentMethod) {
Money total = receipt.getTotal();
Payment p = paymentMethod.acceptPayment(total);
receipt.addPayment(p);
}
Open Closed Principle
public void handleRequest(Request request) {
switch (request.getType()) {
case ACCEPT:
handleAccept(request);
break;
case REJECT:
handleReject(request);
break;
case WITHDRAW:
handleWithdraw(request);
break;
default:
// Hope to never get here.
break;
}
}
public void handleRequest(Request request) {
for (RequestHandler handler : requestHandlers) {
if (handler.accept(request)) {
handler.handle(request);
}
}
}
Liskov Substitution Principle
Interface Segregation Principle
John API: writeCode, playFootball, drinkBeerInterface
Clients
John
Unsupported methodsMatthew
Unsupported methods Adrian Mutu
Services
Luxoft Team Leader Unneeded methods
Football team capitanUnneeded methods Unneeded methods
BuddyUnneeded methods
John API: writeCode, playFootball, drinkBeer
Interface Segregation Principle
John
Matthew
Adrian Mutu
Football team capitan
Luxoft Team Leader
Buddy
Interface
Clients
Services
FootballPlayerProgrammer BeerDrinker
Unsupported methods
Unsupported methods
Unneeded methods
Unneeded methods Unneeded methods
Unneeded methods
Dependency Inversion
Luxoft
Work Procedures
John MatthewAlex
Dependency Inversion
Luxoft
Work Procedures
John MatthewAlex
Programmer QA
Designing with principles - New Project
Never anticipate
Programmers are not the best at anticipating business needs.
Code written in anticipation of a business need is code unused, not tested in real life, getting in
the way.
Anticipatory code create needless abstraction, needless complexity.
YAGN.
Act!
Change the design as soon as needed to respect the principles.
Getting to a design - Legacy Code
Do nothing because
Feeling not authorized or scared to change badly designed code.
The job is overwhelming: too much to understand, change and test.
Fix it all, now!
Take 3 months to make everything perfect.
1 extra month to test everything.
Make it 6 months.
Can’t be done.
The Boy Scouts Rule
When you need to touch existing code, leave it better than you found it.
Add 4 – 8 hours to the task estimate to clean the code and apply the design principles.
Coping with depression
Accept that most code is rotten.
Do not write code that rots easily.
When asking for refactoring time, use non-personal, well educated arguments.
Expect people to agree with you when discussing code quality.
Ignoring design principles affects the company but, most important, it also affects you.
Be the best programmer you can be, regardless of the circumstances.
www.luxoft.com
Thank you
Ionuț Bilică
ionut.bilica@gmail.com
Ad

More Related Content

What's hot (20)

Design principles - SOLID
Design principles - SOLIDDesign principles - SOLID
Design principles - SOLID
Pranalee Rokde
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
Badoo
 
Introduction to .NET Core
Introduction to .NET CoreIntroduction to .NET Core
Introduction to .NET Core
Marco Parenzan
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
Thiago Dos Santos Hora
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
NexThoughts Technologies
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
Mahmoud Asadi
 
Solid principles
Solid principlesSolid principles
Solid principles
Toan Nguyen
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
Neetu Mishra
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
NSCoder Mexico
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
Ganesh Samarthyam
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
Mohamed Galal
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
Nicolas Guignard
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
Rob Gietema
 
2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob 2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob
GEORGE LEON
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
Surendra Shukla
 
Design principles - SOLID
Design principles - SOLIDDesign principles - SOLID
Design principles - SOLID
Pranalee Rokde
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
Badoo
 
Introduction to .NET Core
Introduction to .NET CoreIntroduction to .NET Core
Introduction to .NET Core
Marco Parenzan
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
Mahmoud Asadi
 
Solid principles
Solid principlesSolid principles
Solid principles
Toan Nguyen
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
Neetu Mishra
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
Ganesh Samarthyam
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
Mohamed Galal
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
Rob Gietema
 
2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob 2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob
GEORGE LEON
 

Viewers also liked (6)

SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8
Roland Mast
 
SOLID design principles applied in Java
SOLID design principles applied in JavaSOLID design principles applied in Java
SOLID design principles applied in Java
Bucharest Java User Group
 
SOLID Java Code
SOLID Java CodeSOLID Java Code
SOLID Java Code
Omar Bashir
 
Robert martin
Robert martinRobert martin
Robert martin
Shiraz316
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User Group
Adnan Masood
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
Ganesh Samarthyam
 
SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8
Roland Mast
 
Robert martin
Robert martinRobert martin
Robert martin
Shiraz316
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User Group
Adnan Masood
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
Ganesh Samarthyam
 
Ad

Similar to SOLID Design Principles applied in Java (20)

From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
jonknapp
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
Daniel Fisher
 
Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.
UA Mobile
 
(M) brochure full stack development learning path
(M) brochure full stack development learning path(M) brochure full stack development learning path
(M) brochure full stack development learning path
NirupamNishant2
 
Design patterns
Design patternsDesign patterns
Design patterns
GeekNightHyderabad
 
Backend Development Bootcamp - Node [Online & Offline] In Bangla
Backend Development Bootcamp - Node [Online & Offline] In BanglaBackend Development Bootcamp - Node [Online & Offline] In Bangla
Backend Development Bootcamp - Node [Online & Offline] In Bangla
Stack Learner
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
danhermes
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510
bgenius
 
Introduction to Object oriented Design
Introduction to Object oriented DesignIntroduction to Object oriented Design
Introduction to Object oriented Design
Amin Shahnazari
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
OrisysIndia
 
Agile Software Architecture
Agile Software ArchitectureAgile Software Architecture
Agile Software Architecture
cesarioramos
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Yuvaraj-Resume
Yuvaraj-ResumeYuvaraj-Resume
Yuvaraj-Resume
Yuvaraj Kumar
 
GDSC Backend Bootcamp.pptx
GDSC Backend Bootcamp.pptxGDSC Backend Bootcamp.pptx
GDSC Backend Bootcamp.pptx
SaaraBansode
 
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
DicodingEvent
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Rodolfo Finochietti
 
Going web native
Going web nativeGoing web native
Going web native
Marcus Hellberg
 
Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Do we need SOLID principles during software development?
Do we need SOLID principles during software development?
Anna Shymchenko
 
Android training-in-gurgaon
Android training-in-gurgaonAndroid training-in-gurgaon
Android training-in-gurgaon
AP EDUSOFT
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
jonknapp
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
Daniel Fisher
 
Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.
UA Mobile
 
(M) brochure full stack development learning path
(M) brochure full stack development learning path(M) brochure full stack development learning path
(M) brochure full stack development learning path
NirupamNishant2
 
Backend Development Bootcamp - Node [Online & Offline] In Bangla
Backend Development Bootcamp - Node [Online & Offline] In BanglaBackend Development Bootcamp - Node [Online & Offline] In Bangla
Backend Development Bootcamp - Node [Online & Offline] In Bangla
Stack Learner
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
danhermes
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510
bgenius
 
Introduction to Object oriented Design
Introduction to Object oriented DesignIntroduction to Object oriented Design
Introduction to Object oriented Design
Amin Shahnazari
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
OrisysIndia
 
Agile Software Architecture
Agile Software ArchitectureAgile Software Architecture
Agile Software Architecture
cesarioramos
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
GDSC Backend Bootcamp.pptx
GDSC Backend Bootcamp.pptxGDSC Backend Bootcamp.pptx
GDSC Backend Bootcamp.pptx
SaaraBansode
 
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
DicodingEvent
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Rodolfo Finochietti
 
Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Do we need SOLID principles during software development?
Do we need SOLID principles during software development?
Anna Shymchenko
 
Android training-in-gurgaon
Android training-in-gurgaonAndroid training-in-gurgaon
Android training-in-gurgaon
AP EDUSOFT
 
Ad

Recently uploaded (20)

Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with PrometheusMeet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Eric D. Schabell
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Gojek Clone App for Multi-Service Business
Gojek Clone App for Multi-Service BusinessGojek Clone App for Multi-Service Business
Gojek Clone App for Multi-Service Business
XongoLab Technologies LLP
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
Solar-wind hybrid engery a system sustainable power
Solar-wind  hybrid engery a system sustainable powerSolar-wind  hybrid engery a system sustainable power
Solar-wind hybrid engery a system sustainable power
bhoomigowda12345
 
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEMGDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
philipnathen82
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business StageA Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
SynapseIndia
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with PrometheusMeet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Eric D. Schabell
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Solar-wind hybrid engery a system sustainable power
Solar-wind  hybrid engery a system sustainable powerSolar-wind  hybrid engery a system sustainable power
Solar-wind hybrid engery a system sustainable power
bhoomigowda12345
 
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEMGDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
philipnathen82
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business StageA Comprehensive Guide to CRM Software Benefits for Every Business Stage
A Comprehensive Guide to CRM Software Benefits for Every Business Stage
SynapseIndia
 

SOLID Design Principles applied in Java

  • 6. Why Is Design Important?
  • 9. Martin Fowler’s Design Stamina Hypothesis
  • 11. The primary value of software is that it is soft. That it is resilient in the face of inevitable change. That it not only meets the users' requirements and solves their problems in the present tense, but that it can be readily adapted to meet needs that will arrive tomorrow, or the next day. The Value of Code The Code should do its job, solving a problem that the user has today. The secondary value of software:
  • 12. SOLID Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
  • 13. Design Patterns vs Design Principles
  • 17. Single Responsibility Principle A class should have one, and only one, reason to change. Open Closed Principle You should be able to extend a classes behavior, without modifying it. Common Closure Principle Classes that change together are packaged together.
  • 18. Single Responsibility Principle A class should have one, and only one, reason to change. Open Closed Principle You should be able to extend a classes behavior, without modifying it. Common Closure Principle Classes that change together are packaged together.
  • 19. Why does software changes? A change is requested by the product owner through a user story. A user story relates to a business capability of the software. A user story is written in business language. A change comes as a user story, for a business capability, and is written in business language.
  • 20. Single Responsibility Principle A class should have one, and only one, reason to change. Open Closed Principle You should be able to extend a classes behavior, without modifying it. Common Closure Principle Classes that change together are packaged together.
  • 24. Single Responsibility Principle private String assemblyDirections() { String directions = "You can go"; for (Direction to : Direction.values()) { if (canMoveTo(to)) { directions += " " + to; } } directions += " from here."; return directions; } private List<Direction> getAvailableDirections() { List<Direction> directions = new ArrayList<>(); for (Direction to : Direction.values()) { if (canMoveTo(to)) { directions.add(to); } } return directions; } private String describe(Direction[] directions) { String str = "You can go"; for (int i=0; i<directions.length; i++) { str += " " + directions[i]; } str += " from here."; return directionsStr; }
  • 25. Single Responsibility Principle public class ResponseBuilder { public Document buildReponseForAccept(int dealId) { //Create service response for Accept request. //... } public Document buildReponseForReject(int dealId, String reason) { //Create service response for Reject request. //... } public Document buildReponseForUpdate(int dealId, DealDiff diff) { //Create service response for Update request. //... } public Document buildResponseForWithdraw(int dealId) { //Create service response for Update request. //... } }
  • 26. Single Responsibility Principle public class Configuration { //... public String getHost() { return host; } public int getPort() { return port; } public boolean startInMaximizedWindow() { return port; } public Color getMainThemeColor() { return mainThrmeColor; } } public static class ConnectionFactory { private final String host; private final int port; @Inject public ConnectionFactory(@Config String host, @Config int port) { this.host = host; this.port = port; } //... }
  • 27. Breaking the Single Responsibility Principle Break unrelated code Unrelated tests fail Unrelated functionality breaks Blame is thrown around Clients panic and build mistrust
  • 28. Open Closed Principle public void checkout(Receipt receipt) { Money total = receipt.getTotal(); Payment p = acceptCash(total); receipt.addPayment(p); } public void checkout(Receipt receipt, PaymentMethodType paymentMethodType) { Money total = receipt.getTotal(); Payment p = null; if (paymentMethodType == CASH) { p = acceptCash(total); } else if (paymentMethodType == CREDIT) { p = acceptCredit(total); } else { // There's no way to reached this. I hope. } receipt.addPayment(p); } public void checkout(Receipt receipt, PaymentMethod paymentMethod) { Money total = receipt.getTotal(); Payment p = paymentMethod.acceptPayment(total); receipt.addPayment(p); }
  • 29. Open Closed Principle public void handleRequest(Request request) { switch (request.getType()) { case ACCEPT: handleAccept(request); break; case REJECT: handleReject(request); break; case WITHDRAW: handleWithdraw(request); break; default: // Hope to never get here. break; } } public void handleRequest(Request request) { for (RequestHandler handler : requestHandlers) { if (handler.accept(request)) { handler.handle(request); } } }
  • 31. Interface Segregation Principle John API: writeCode, playFootball, drinkBeerInterface Clients John Unsupported methodsMatthew Unsupported methods Adrian Mutu Services Luxoft Team Leader Unneeded methods Football team capitanUnneeded methods Unneeded methods BuddyUnneeded methods
  • 32. John API: writeCode, playFootball, drinkBeer Interface Segregation Principle John Matthew Adrian Mutu Football team capitan Luxoft Team Leader Buddy Interface Clients Services FootballPlayerProgrammer BeerDrinker Unsupported methods Unsupported methods Unneeded methods Unneeded methods Unneeded methods Unneeded methods
  • 35. Designing with principles - New Project Never anticipate Programmers are not the best at anticipating business needs. Code written in anticipation of a business need is code unused, not tested in real life, getting in the way. Anticipatory code create needless abstraction, needless complexity. YAGN. Act! Change the design as soon as needed to respect the principles.
  • 36. Getting to a design - Legacy Code Do nothing because Feeling not authorized or scared to change badly designed code. The job is overwhelming: too much to understand, change and test. Fix it all, now! Take 3 months to make everything perfect. 1 extra month to test everything. Make it 6 months. Can’t be done. The Boy Scouts Rule When you need to touch existing code, leave it better than you found it. Add 4 – 8 hours to the task estimate to clean the code and apply the design principles.
  • 37. Coping with depression Accept that most code is rotten. Do not write code that rots easily. When asking for refactoring time, use non-personal, well educated arguments. Expect people to agree with you when discussing code quality. Ignoring design principles affects the company but, most important, it also affects you. Be the best programmer you can be, regardless of the circumstances.
  翻译: