SlideShare a Scribd company logo
Code and design smells.
Are they a real threat?
Antoni Rasul
Lehman's laws of software evolution
• Originally formulated by Manny Lehman in 1974 and later
refined, as a result of empirical study within IBM
• Aimed at finding scientific properties of evolution of
different classes of software
• System types:
• S-type (specified) Systems
• P-type (problem solving) Systems
• E-type (evolutionary) Systems
E-type Systems laws of evolution (since 1996)
I. Continuing Change
II. Increasing Complexity
III. Self Regulation
IV. Conservation of Organizational Stability
V. Conservation of Familiarity
VI. Continuing Growth
VII. Declining Quality
VIII.Feedback System
Technical debt
• Monetary metaphor
• Impossible to measure precisely
• If not repaid regularly – accumulates interest
Time
Effort
Interest
payment
Feature
Warning signs of rising debt
• The quality of your software is degrading
• The bug backlog is increasing
• The bug threshold in release is rising
• Your productivity is slipping
• Fictional deadlines
• The team members don't care
Effective ways to reduce the debt
• Define the debt
• Revise the Definition of Done
• Testing tasks part of story
• Done means code cleaned, refactored, deployed and tested
• Use tools like Sonar to visualise (also for management)
• Refactor
• Identify code smells and plan for change
• Automate
Refactoring
• Refactoring: a change made to the internal structure of
software to make it easier to understand and cheaper to
modify without changing its observable behavior.
• Refactor when:
• Adding a function
• Fixing a bug
• Doing a code review
• Perform larger refactorings in small increments
Code smells
• Duplicated Code
• Shotgun surgery
• Feature envy
• Switch statements
• Refused bequest
• Telescoping constructors
• Big Ball of Mud
Techniques
• Extract method/class
• Substitute algorithm
• Introduce parameter object
• Replace type conditional with Polymorphism/Strategy
• Fluent interface with Essence pattern
Duplicated Code or Structure
• In same class
 Extract Method
• In sibling classes
 Extract Method
 Pull method Up
• In unrelated classes
 Substitute algorithm
 Extract Class
 Use extracted class in other places
Shotgun surgery
• Adding simple feature requires small changes in gazillion
classes
• Difficult to eliminate in big systems
• Removing duplicates first – reduces the smell
• Code generation tools help reduce the problem further
Feature envy
• One class’s method is extensively using data and methods
of another class
• Usually easy to spot and fix – move the method to the class
where it belongs
• If method uses several classes – move it to the one with
most used data
• Use Move Method, possibly with Extract Method
Switch by type in multiple places - problem
public class PriceCalculator {
public double calculatePrice(Customer customer, Car car, Period period) {
double tax = 0;
double discount = 0;
switch(customer.getType()) {
case REGULAR:
discount = 0;
tax = 0.2;
case BUSINESS:
discount = 0.5;
tax = 0.2;
case BIG_BUSINESS:
discount = 0.2;
tax = 0.1;
}
return period.getDays() * car.getDayPrice() * (1 - discount * tax);
}
}
Switch by type - Replace type code by
polymorphism
public interface Customer {
CustomerType getType();
}
public interface CustomerType {
double getDiscount();
double getTax();
}
public class RegularCustomer implements CustomerType {
...
}
public class BusinessCustomer implements CustomerType {
...
}
public class BigBusinessCustomer implements CustomerType {
...
}
Switch by type - refactored
public class PriceCalculator {
public double calculatePrice(Customer customer, Car car, Period period) {
final double tax = customer.getType().getTax();
final double discount = customer.getType().getDiscount();
return period.getDays() * car.getDayPrice() * (1 - discount * tax);
}
}
• If price calculation algorithm would depend on Customer type –
use Strategy
Refused bequest
public interface Car {
String getModel();
double getDayPrice();
}
public class Truck implements Car {
public String getMaxCargoVolume(){...};
}
public class CarFleet implements Car {
private List<Car> cars;
public String getModel() {
return null; // Hmmmmm Let's return null here 
}
public double getDayPrice() {
return this.cars.stream().mapToDouble(c -> c.getDayPrice()).sum();
}
}
• When subclass inherits data/methods that it doesn’t want
• When sublcass refuses to meaningfully implement all interface methods
Refused bequest - ideas
• Hierarchy is wrong
• Reshuffle hierarchy, so that parent contains only what’s common
• Another solution – pull the violating class out of the hierarchy and
use a delegate to the instance of (former) parent class
Refused bequest – example refactored
public interface RentableItem {
double getDayPrice();
}
public interface Car extends RentableItem {
String getModel();
}
public interface CarFleet extends RentableItem {
double getFleetDiscount();
}
public class StandardFleet implements CarFleet {
private List<Car> cars;
public double getDayPrice() {
return this.cars.stream().mapToDouble(c -> c.getDayPrice()).sum();
}
public double getFleetDiscount() {
return 0.1;
}
}
Telescoping constructors
public class RentalContract {
...
public RentalContract(Customer cust, List<Car> cars, Date startDate) {
this(cust, car, startDate, null);
}
public RentalContract(Customer cust, List<Car> cars, Date startDate, Date endDate) {
this(cust, cars, null, null, startDate, endDate);
}
public RentalContract(Customer customer, List<Car> cars, BigDecimal extraDiscount,
String description, Date startDate, Date endDate) {
this.customer = customer;
this.cars = cars;
this.extraDiscount = extraDiscount;
this.description = description;
this.startDate = startDate;
this.endDate = endDate;
}
...
}
Telescoping constructors – required fields
public RentalContract(
Customer customer,
List<Car> cars,
BigDecimal extraDiscount,
String description,
Date startDate,
Date endDate)
{...}
• Instantiating is cumbersome, error-prone
• Optional fields are mixed with required ones
Telescoping constructors – refactoring ideas
• Introduce parameter object from startDate and endDate
public class DateRange {
private Date start;
private Date end;
...
public DateRange withStart(Date start) {
this.start = start;
return this;
}
public DateRange withEnd(Date end) {
this.end = end;
return this;
}
}
• Use Essence pattern composed of:
• Builder
• Fluent interface
• Validation of required fields before object construction
Telescoping constructors – fluent builder
public class RentalContractBuilder {
...
public RentalContractBuilder withCustomer(Customer customer) {
this.customer = customer;
return this;
}
public RentalContractBuilder addCar(Car car) {
cars.add(car);
return this;
}
public RentalContractBuilder withCars(List<Car> cars) {
this.cars = cars;
return this;
}
public RentalContractBuilder withDateRange(DateRange dateRange) {
this.dateRange = dateRange;
return this;
}
public void validate() {
customerValidator.validate(customer);
carValidator.validate(cars);
datesValidator.validate(dateRange);
}
public RentalContract build() {
validate();
return new RentalContract(this);
}
}
Telescoping constructors – end result
public class RentalContract {
...
RentalContract(RentalContractBuilder contractBuilder) {
this.customer = contractBuilder.getCustomer();
this.cars = contractBuilder.getCars();
this.dateRange = contractBuilder.getDateRange();
}
}
RentalContract rentalContract = new RentalContractBuilder()
.withCustomer(customer)
.addCar(mustang)
.addCar(camaro)
.withDateRange(new DateRange().withStart(new Date()))
.build();
• Constructor with default access
• We are sure that rentalContract is a valid instance after build()
Big Ball of Mud – The Mikado Method
• Allows for systematic reshaping of the system
• Easy to use
• Provides stability to the codebase while changing it
• Fits in an incremental process
• Scalable, the whole team can participate
The Mikado Method
• Set a goal
• Experiment
• Visualize
• Undo
The Mikado Method - flow
Draw goal
Implement goal
naively
Errors?
Come up with immediate
solutions and draw them as
sub-goals
Revert changes
Select next goal
Yes
No Change
makes sense?
Check in !
All goals
completed?
Done!
Yes
Yes
Yes
No
No
Mikado graph
Mikado
Goal
Prerequisite:
immediate
solution
Another
prerequisite
More
prerequisites ..linked to
previous
Can have
common
dependencies
Summary
• Forgive the predecessors
• Take small steps
• Work as a team
• Convince management
• Willingness to change

More Related Content

What's hot

Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
MLG College of Learning, Inc
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
MLG College of Learning, Inc
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
MLG College of Learning, Inc
 
Unit 3
Unit 3Unit 3
Unit 1
Unit 1Unit 1
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
MLG College of Learning, Inc
 
MDA with Executable UML
MDA with Executable UMLMDA with Executable UML
MDA with Executable UML
Chris Raistrick
 
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and AnimationChapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
Nicole Ryan
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
Nicole Ryan
 
Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
Jyothishmathi Institute of Technology and Science Karimnagar
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
MLG College of Learning, Inc
 
Improvised Architeture of visual attention model
Improvised Architeture of visual attention modelImprovised Architeture of visual attention model
Improvised Architeture of visual attention model
Ravi Kiran Chadalawada
 
Lesson 5.2 logical operators
Lesson 5.2 logical operatorsLesson 5.2 logical operators
Lesson 5.2 logical operators
MLG College of Learning, Inc
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
Taymoor Nazmy
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
C basics
C basicsC basics
C basics
sridevi5983
 
20100309 02 - Software testing (McCabe)
20100309 02 - Software testing (McCabe)20100309 02 - Software testing (McCabe)
20100309 02 - Software testing (McCabe)
LeClubQualiteLogicielle
 
Unit 5
Unit 5Unit 5
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Ashish Meshram
 

What's hot (20)

Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 1
Unit 1Unit 1
Unit 1
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
 
MDA with Executable UML
MDA with Executable UMLMDA with Executable UML
MDA with Executable UML
 
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and AnimationChapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
 
Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
Improvised Architeture of visual attention model
Improvised Architeture of visual attention modelImprovised Architeture of visual attention model
Improvised Architeture of visual attention model
 
Lesson 5.2 logical operators
Lesson 5.2 logical operatorsLesson 5.2 logical operators
Lesson 5.2 logical operators
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
C basics
C basicsC basics
C basics
 
20100309 02 - Software testing (McCabe)
20100309 02 - Software testing (McCabe)20100309 02 - Software testing (McCabe)
20100309 02 - Software testing (McCabe)
 
Unit 5
Unit 5Unit 5
Unit 5
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 

Similar to Code and Design Smells. Are They a Real Threat?

Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
Neoito
 
MDE in Practice
MDE in PracticeMDE in Practice
MDE in Practice
Abdalmassih Yakeen
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
Abed Bukhari
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
Chris Renner
 
CPP15 - Inheritance
CPP15 - InheritanceCPP15 - Inheritance
CPP15 - Inheritance
Michael Heron
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2
Ruben Haeck
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
vmandrychenko
 
AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...
Institute of Contemporary Sciences
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Iván Fernández Perea
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
saifnasir3
 
CIS110 Computer Programming Design Chapter (9)
CIS110 Computer Programming Design Chapter  (9)CIS110 Computer Programming Design Chapter  (9)
CIS110 Computer Programming Design Chapter (9)
Dr. Ahmed Al Zaidy
 
14method in c#
14method in c#14method in c#
14method in c#
Sireesh K
 
Project Estimation
Project EstimationProject Estimation
Project Estimation
Kasun Ranga Wijeweera
 
Man.ppt
Man.pptMan.ppt
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
PowerfullBoy1
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IV
Hari Christian
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11
Ben Abdallah Helmi
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 

Similar to Code and Design Smells. Are They a Real Threat? (20)

Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
 
MDE in Practice
MDE in PracticeMDE in Practice
MDE in Practice
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
CPP15 - Inheritance
CPP15 - InheritanceCPP15 - Inheritance
CPP15 - Inheritance
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
 
AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
CIS110 Computer Programming Design Chapter (9)
CIS110 Computer Programming Design Chapter  (9)CIS110 Computer Programming Design Chapter  (9)
CIS110 Computer Programming Design Chapter (9)
 
14method in c#
14method in c#14method in c#
14method in c#
 
Project Estimation
Project EstimationProject Estimation
Project Estimation
 
Man.ppt
Man.pptMan.ppt
Man.ppt
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IV
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 

More from GlobalLogic Ukraine

GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Ukraine
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic Ukraine
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptxШтучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptx
GlobalLogic Ukraine
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptxЗадачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptx
GlobalLogic Ukraine
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptxЩо треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Ukraine
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic Ukraine
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic Ukraine
 
Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic Ukraine
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic Ukraine
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic Ukraine
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Ukraine
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic Ukraine
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic Ukraine
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Ukraine
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
GlobalLogic Ukraine
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Ukraine
 

More from GlobalLogic Ukraine (20)

GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptxШтучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptx
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptxЗадачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptx
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptxЩо треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
 
Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
 

Recently uploaded

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 

Recently uploaded (20)

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 

Code and Design Smells. Are They a Real Threat?

  • 1. Code and design smells. Are they a real threat? Antoni Rasul
  • 2. Lehman's laws of software evolution • Originally formulated by Manny Lehman in 1974 and later refined, as a result of empirical study within IBM • Aimed at finding scientific properties of evolution of different classes of software • System types: • S-type (specified) Systems • P-type (problem solving) Systems • E-type (evolutionary) Systems
  • 3. E-type Systems laws of evolution (since 1996) I. Continuing Change II. Increasing Complexity III. Self Regulation IV. Conservation of Organizational Stability V. Conservation of Familiarity VI. Continuing Growth VII. Declining Quality VIII.Feedback System
  • 4. Technical debt • Monetary metaphor • Impossible to measure precisely • If not repaid regularly – accumulates interest Time Effort Interest payment Feature
  • 5. Warning signs of rising debt • The quality of your software is degrading • The bug backlog is increasing • The bug threshold in release is rising • Your productivity is slipping • Fictional deadlines • The team members don't care
  • 6. Effective ways to reduce the debt • Define the debt • Revise the Definition of Done • Testing tasks part of story • Done means code cleaned, refactored, deployed and tested • Use tools like Sonar to visualise (also for management) • Refactor • Identify code smells and plan for change • Automate
  • 7. Refactoring • Refactoring: a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. • Refactor when: • Adding a function • Fixing a bug • Doing a code review • Perform larger refactorings in small increments
  • 8. Code smells • Duplicated Code • Shotgun surgery • Feature envy • Switch statements • Refused bequest • Telescoping constructors • Big Ball of Mud
  • 9. Techniques • Extract method/class • Substitute algorithm • Introduce parameter object • Replace type conditional with Polymorphism/Strategy • Fluent interface with Essence pattern
  • 10. Duplicated Code or Structure • In same class  Extract Method • In sibling classes  Extract Method  Pull method Up • In unrelated classes  Substitute algorithm  Extract Class  Use extracted class in other places
  • 11. Shotgun surgery • Adding simple feature requires small changes in gazillion classes • Difficult to eliminate in big systems • Removing duplicates first – reduces the smell • Code generation tools help reduce the problem further
  • 12. Feature envy • One class’s method is extensively using data and methods of another class • Usually easy to spot and fix – move the method to the class where it belongs • If method uses several classes – move it to the one with most used data • Use Move Method, possibly with Extract Method
  • 13. Switch by type in multiple places - problem public class PriceCalculator { public double calculatePrice(Customer customer, Car car, Period period) { double tax = 0; double discount = 0; switch(customer.getType()) { case REGULAR: discount = 0; tax = 0.2; case BUSINESS: discount = 0.5; tax = 0.2; case BIG_BUSINESS: discount = 0.2; tax = 0.1; } return period.getDays() * car.getDayPrice() * (1 - discount * tax); } }
  • 14. Switch by type - Replace type code by polymorphism public interface Customer { CustomerType getType(); } public interface CustomerType { double getDiscount(); double getTax(); } public class RegularCustomer implements CustomerType { ... } public class BusinessCustomer implements CustomerType { ... } public class BigBusinessCustomer implements CustomerType { ... }
  • 15. Switch by type - refactored public class PriceCalculator { public double calculatePrice(Customer customer, Car car, Period period) { final double tax = customer.getType().getTax(); final double discount = customer.getType().getDiscount(); return period.getDays() * car.getDayPrice() * (1 - discount * tax); } } • If price calculation algorithm would depend on Customer type – use Strategy
  • 16. Refused bequest public interface Car { String getModel(); double getDayPrice(); } public class Truck implements Car { public String getMaxCargoVolume(){...}; } public class CarFleet implements Car { private List<Car> cars; public String getModel() { return null; // Hmmmmm Let's return null here  } public double getDayPrice() { return this.cars.stream().mapToDouble(c -> c.getDayPrice()).sum(); } } • When subclass inherits data/methods that it doesn’t want • When sublcass refuses to meaningfully implement all interface methods
  • 17. Refused bequest - ideas • Hierarchy is wrong • Reshuffle hierarchy, so that parent contains only what’s common • Another solution – pull the violating class out of the hierarchy and use a delegate to the instance of (former) parent class
  • 18. Refused bequest – example refactored public interface RentableItem { double getDayPrice(); } public interface Car extends RentableItem { String getModel(); } public interface CarFleet extends RentableItem { double getFleetDiscount(); } public class StandardFleet implements CarFleet { private List<Car> cars; public double getDayPrice() { return this.cars.stream().mapToDouble(c -> c.getDayPrice()).sum(); } public double getFleetDiscount() { return 0.1; } }
  • 19. Telescoping constructors public class RentalContract { ... public RentalContract(Customer cust, List<Car> cars, Date startDate) { this(cust, car, startDate, null); } public RentalContract(Customer cust, List<Car> cars, Date startDate, Date endDate) { this(cust, cars, null, null, startDate, endDate); } public RentalContract(Customer customer, List<Car> cars, BigDecimal extraDiscount, String description, Date startDate, Date endDate) { this.customer = customer; this.cars = cars; this.extraDiscount = extraDiscount; this.description = description; this.startDate = startDate; this.endDate = endDate; } ... }
  • 20. Telescoping constructors – required fields public RentalContract( Customer customer, List<Car> cars, BigDecimal extraDiscount, String description, Date startDate, Date endDate) {...} • Instantiating is cumbersome, error-prone • Optional fields are mixed with required ones
  • 21. Telescoping constructors – refactoring ideas • Introduce parameter object from startDate and endDate public class DateRange { private Date start; private Date end; ... public DateRange withStart(Date start) { this.start = start; return this; } public DateRange withEnd(Date end) { this.end = end; return this; } } • Use Essence pattern composed of: • Builder • Fluent interface • Validation of required fields before object construction
  • 22. Telescoping constructors – fluent builder public class RentalContractBuilder { ... public RentalContractBuilder withCustomer(Customer customer) { this.customer = customer; return this; } public RentalContractBuilder addCar(Car car) { cars.add(car); return this; } public RentalContractBuilder withCars(List<Car> cars) { this.cars = cars; return this; } public RentalContractBuilder withDateRange(DateRange dateRange) { this.dateRange = dateRange; return this; } public void validate() { customerValidator.validate(customer); carValidator.validate(cars); datesValidator.validate(dateRange); } public RentalContract build() { validate(); return new RentalContract(this); } }
  • 23. Telescoping constructors – end result public class RentalContract { ... RentalContract(RentalContractBuilder contractBuilder) { this.customer = contractBuilder.getCustomer(); this.cars = contractBuilder.getCars(); this.dateRange = contractBuilder.getDateRange(); } } RentalContract rentalContract = new RentalContractBuilder() .withCustomer(customer) .addCar(mustang) .addCar(camaro) .withDateRange(new DateRange().withStart(new Date())) .build(); • Constructor with default access • We are sure that rentalContract is a valid instance after build()
  • 24. Big Ball of Mud – The Mikado Method • Allows for systematic reshaping of the system • Easy to use • Provides stability to the codebase while changing it • Fits in an incremental process • Scalable, the whole team can participate
  • 25. The Mikado Method • Set a goal • Experiment • Visualize • Undo
  • 26. The Mikado Method - flow Draw goal Implement goal naively Errors? Come up with immediate solutions and draw them as sub-goals Revert changes Select next goal Yes No Change makes sense? Check in ! All goals completed? Done! Yes Yes Yes No No
  • 28. Summary • Forgive the predecessors • Take small steps • Work as a team • Convince management • Willingness to change