SlideShare a Scribd company logo
© XPSurgery.com 2016 @kevinrutherford
Love and Death
“To love is to suffer. To avoid suffering
one must not love. But then one
suffers from not loving. Therefore,
to love is to suffer; not to love is to
suffer; to suffer is to suffer. To be
happy is to love. To be happy,
then, is to suffer, but suffering
makes one unhappy. Therefore,
to be unhappy, one must love or
love to suffer or suffer from too
much happiness.
I hope you're getting this down.”
Love and Death, Woody Allen, 1975
© XPSurgery.com 2016 @kevinrutherford
@kevinrutherford @xpsurgery
http://silkandspinach.net http://xpsurgery.com
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Extreme Normal Form:
1. Passes all tests
2. Expresses intent
3. No duplication
4. No extra stuff
© XPSurgery.com 2016 @kevinrutherford
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphism
Lazy Class
Temporary Field
Inappropriate
Intim
acy
ShotgunSurgery
Data Clump
Long
M
ethod
Large Class
???
??? ???
???
???
???
???
RefusedBequest
© XPSurgery.com 2016 @kevinrutherford
S ingle responsibility principle
O pen-closed principle
L iskov substitution principle
I nterface segregation principle
D ependency inversion principle
© XPSurgery.com 2016 @kevinrutherford
Principles of package cohesion
Reuse-release equivalence principle (REP)
Common-reuse principle (CRP)
Common-closure principle (CCP)
Principles of package coupling
Acyclic dependencies principle (ADP)
Stable-dependencies principle (SDP)
Stable-abstractions principle (SAP)
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
“This is Mrs Bencours,
one of my patients.
She thinks she's a sheep.”
Everything you always wanted to know about sex
but were afraid to ask, Woody Allen, 1975
coupling
© XPSurgery.com 2016 @kevinrutherford
Comparing Techniques by Means of Encapsulation
and Connascence,
Communications of the ACM Vol. 35, No. 9, Sept. 1992
pp. 147-151
Meilir
Page-Jones
© XPSurgery.com 2016 @kevinrutherford
1996
Meilir
Page-Jones
© XPSurgery.com 2016 @kevinrutherford
1999
Meilir
Page-Jones
© XPSurgery.com 2016 @kevinrutherford
Connascence between two software elements
A and B means either:
1) some change to A would require B to be changed, or
2) some change would require both A and B to be changed together
in order to preserve overall correctness.
© XPSurgery.com 2016 @kevinrutherford
Connascence between two software elements
A and B means either:
1) some change to A would require B to be changed,
(or at least carefully checked), or
2) some change would require both A and B to be changed together
in order to preserve overall correctness.
© XPSurgery.com 2016 @kevinrutherford
Meilir
Page-Jones
“I'll go so far as to say
that connascence [is]
at the heart of modern
software-engineering
constructs.”
© XPSurgery.com 2016 @kevinrutherford
2005-9
Grand Unified Theory
of Software Design
Jim
Weirich
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
Degree
Type
Reach
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
N
N N
N
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
A
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
hash(...)
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
hash(...)
A
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Position
printf(“%d %sn”, time.now(), request.path);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Position
printf(“%d %sn”, time.now(), request.path);
P
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Convention
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal salesTax = calcTax(basePrice);
return basePrice + salesTax;
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Convention
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal salesTax = calcTax(basePrice);
return basePrice + salesTax;
C
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Type
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal salesTax = calcTax(basePrice);
return basePrice + salesTax;
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Type
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal salesTax = calcTax(basePrice);
return basePrice + salesTax;
T
[static]
© XPSurgery.com 2016 @kevinrutherford
Static connascence:
Name Convention
Algorithm Type
Position (Difference)
© XPSurgery.com 2016 @kevinrutherford
string[] board = new string[12];
     :
     :
if (position[currentPlayer] > 11)
  index = 0;
Connascence of Value
[dynamic]
© XPSurgery.com 2016 @kevinrutherford
string[] board = new string[12];
     :
     :
if (position[currentPlayer] > 11)
  index = 0;
Connascence of Value
[dynamic]
V
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydomain.com")
email.setSubject("Hello World")
email.send()
Connascence of Execution
[dynamic]
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydomain.com")
email.setSubject("Hello World")
email.send()
Connascence of Execution
[dynamic]
E
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydomain.com")
email.setSubject("Hello World")
email.send()
Connascence of Execution
[dynamic]
E
E
© XPSurgery.com 2016 @kevinrutherford
Connascence of Identity
[dynamic]
fetch(`http://localhost:17174/salesmen/${salesmanId}`, {
  method: 'put',
  body: JSON.stringify({
    salesmanId: salesmanId,
    orderId: orderId,
    commission: commission
  })
})
© XPSurgery.com 2016 @kevinrutherford
Connascence of Identity
[dynamic]
fetch(`http://localhost:17174/salesmen/${salesmanId}`, {
  method: 'put',
  body: JSON.stringify({
    salesmanId: salesmanId,
    orderId: orderId,
    commission: commission
  })
}) I
© XPSurgery.com 2016 @kevinrutherford
Connascence of Timing
[dynamic]
xrayMachine.on()
Thread.sleep(20)
xrayMachine.off()
© XPSurgery.com 2016 @kevinrutherford
Connascence of Timing
[dynamic]
xrayMachine.on()
Thread.sleep(20)
xrayMachine.off()
T
© XPSurgery.com 2016 @kevinrutherford
Dynamic connascence:
Value Timing
Execution (Difference)
Identity
© XPSurgery.com 2016 @kevinrutherford
Degree
Type
Reach
© XPSurgery.com 2016 @kevinrutherford
50
50
V = 2
E = 1
© XPSurgery.com 2016 @kevinrutherford
50
50
50
V = 3
E = 3
© XPSurgery.com 2016 @kevinrutherford
50
50
50
50
V = 4
E = 6
© XPSurgery.com 2016 @kevinrutherford
V = 5
E = 10
50
50
50
50
50
© XPSurgery.com 2016 @kevinrutherford
Type
Degree
Reach
© XPSurgery.com 2016 @kevinrutherford
expression ↔ expression 0
function ↔ function 1
object ↔ object 2
aggregate ↔ aggregate 3
process ↔ process 4
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation boundaries
By breaking the system into
encapsulated elements
By maximising the connascence
within encapsulation boundaries
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation boundaries
By breaking the system into
encapsulated elements
By maximising the connascence
within encapsulation boundaries
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
By breaking the system into
encapsulated elements
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Ca,b
= f(type, level, degree)
?
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
© XPSurgery.com 2016 @kevinrutherford
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphism
Lazy Class
Temporary Field
Inappropriate
Intim
acy
ShotgunSurgery
Data Clump
Long
M
ethod
Large Class
???
??? ???
???
???
???
???
RefusedBequest
© XPSurgery.com 2016 @kevinrutherford
“I'll go so far as to say
that connascence [is]
at the heart of modern
software-engineering
constructs.”
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation boundaries
By breaking the system into
encapsulated elements
By maximising the connascence
within encapsulation boundaries
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Ca,b
= f(type, level, degree)
© XPSurgery.com 2016 @kevinrutherford
1. Break the monolith you have into
meaningful encapsulation units
2. Remove the “worst” connascence among
the encapsulation units
3. Find which encapsulation units have
the “most” internal connascence
4. Recurse into each, returning to the
top level after each one
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
@kevinrutherford
@xpsurgery
http://silkandspinach.net/tag/connascence
http://xpsurgery.com

More Related Content

More from Kevin Rutherford

OCP String Calculator kata
OCP String Calculator kataOCP String Calculator kata
OCP String Calculator kataKevin Rutherford
 
Flow
FlowFlow

More from Kevin Rutherford (14)

Hex arch
Hex archHex arch
Hex arch
 
Shepherding antipatterns
Shepherding antipatternsShepherding antipatterns
Shepherding antipatterns
 
Kata rules
Kata rulesKata rules
Kata rules
 
Movie app kata
Movie app kataMovie app kata
Movie app kata
 
Object discovery
Object discoveryObject discovery
Object discovery
 
Connascence
ConnascenceConnascence
Connascence
 
OCP Checkout kata
OCP Checkout kataOCP Checkout kata
OCP Checkout kata
 
OCP bowling kata
OCP bowling kataOCP bowling kata
OCP bowling kata
 
OCP String Calculator kata
OCP String Calculator kataOCP String Calculator kata
OCP String Calculator kata
 
OCP kata overview
OCP kata overviewOCP kata overview
OCP kata overview
 
Telling not-asking
Telling not-askingTelling not-asking
Telling not-asking
 
Uml
UmlUml
Uml
 
Agile principles
Agile principlesAgile principles
Agile principles
 
Flow
FlowFlow
Flow
 

Recently uploaded

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Love and death

  • 1. © XPSurgery.com 2016 @kevinrutherford Love and Death “To love is to suffer. To avoid suffering one must not love. But then one suffers from not loving. Therefore, to love is to suffer; not to love is to suffer; to suffer is to suffer. To be happy is to love. To be happy, then, is to suffer, but suffering makes one unhappy. Therefore, to be unhappy, one must love or love to suffer or suffer from too much happiness. I hope you're getting this down.” Love and Death, Woody Allen, 1975
  • 2. © XPSurgery.com 2016 @kevinrutherford @kevinrutherford @xpsurgery http://silkandspinach.net http://xpsurgery.com
  • 3. © XPSurgery.com 2016 @kevinrutherford
  • 4. © XPSurgery.com 2016 @kevinrutherford
  • 5. © XPSurgery.com 2016 @kevinrutherford ?
  • 6. © XPSurgery.com 2016 @kevinrutherford
  • 7. © XPSurgery.com 2016 @kevinrutherford
  • 8. © XPSurgery.com 2016 @kevinrutherford Extreme Normal Form: 1. Passes all tests 2. Expresses intent 3. No duplication 4. No extra stuff
  • 9. © XPSurgery.com 2016 @kevinrutherford Primitive Obsession Feature Envy Sim ulated Polym orphism Lazy Class Temporary Field Inappropriate Intim acy ShotgunSurgery Data Clump Long M ethod Large Class ??? ??? ??? ??? ??? ??? ??? RefusedBequest
  • 10. © XPSurgery.com 2016 @kevinrutherford S ingle responsibility principle O pen-closed principle L iskov substitution principle I nterface segregation principle D ependency inversion principle
  • 11. © XPSurgery.com 2016 @kevinrutherford Principles of package cohesion Reuse-release equivalence principle (REP) Common-reuse principle (CRP) Common-closure principle (CCP) Principles of package coupling Acyclic dependencies principle (ADP) Stable-dependencies principle (SDP) Stable-abstractions principle (SAP)
  • 12. © XPSurgery.com 2016 @kevinrutherford
  • 13. © XPSurgery.com 2016 @kevinrutherford
  • 14. © XPSurgery.com 2016 @kevinrutherford “This is Mrs Bencours, one of my patients. She thinks she's a sheep.” Everything you always wanted to know about sex but were afraid to ask, Woody Allen, 1975 coupling
  • 15. © XPSurgery.com 2016 @kevinrutherford Comparing Techniques by Means of Encapsulation and Connascence, Communications of the ACM Vol. 35, No. 9, Sept. 1992 pp. 147-151 Meilir Page-Jones
  • 16. © XPSurgery.com 2016 @kevinrutherford 1996 Meilir Page-Jones
  • 17. © XPSurgery.com 2016 @kevinrutherford 1999 Meilir Page-Jones
  • 18. © XPSurgery.com 2016 @kevinrutherford Connascence between two software elements A and B means either: 1) some change to A would require B to be changed, or 2) some change would require both A and B to be changed together in order to preserve overall correctness.
  • 19. © XPSurgery.com 2016 @kevinrutherford Connascence between two software elements A and B means either: 1) some change to A would require B to be changed, (or at least carefully checked), or 2) some change would require both A and B to be changed together in order to preserve overall correctness.
  • 20. © XPSurgery.com 2016 @kevinrutherford Meilir Page-Jones “I'll go so far as to say that connascence [is] at the heart of modern software-engineering constructs.”
  • 21. © XPSurgery.com 2016 @kevinrutherford 2005-9 Grand Unified Theory of Software Design Jim Weirich
  • 22. © XPSurgery.com 2016 @kevinrutherford
  • 23. © XPSurgery.com 2016 @kevinrutherford
  • 24. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  • 25. © XPSurgery.com 2016 @kevinrutherford Degree Type Reach
  • 26. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  • 27. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  • 28. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  • 29. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  • 30. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); N N N N [static]
  • 31. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) [static]
  • 32. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) A [static]
  • 33. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) hash(...) [static]
  • 34. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) hash(...) A [static]
  • 35. © XPSurgery.com 2016 @kevinrutherford Connascence of Position printf(“%d %sn”, time.now(), request.path); [static]
  • 36. © XPSurgery.com 2016 @kevinrutherford Connascence of Position printf(“%d %sn”, time.now(), request.path); P [static]
  • 37. © XPSurgery.com 2016 @kevinrutherford Connascence of Convention int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; [static]
  • 38. © XPSurgery.com 2016 @kevinrutherford Connascence of Convention int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; C [static]
  • 39. © XPSurgery.com 2016 @kevinrutherford Connascence of Type int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; [static]
  • 40. © XPSurgery.com 2016 @kevinrutherford Connascence of Type int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; T [static]
  • 41. © XPSurgery.com 2016 @kevinrutherford Static connascence: Name Convention Algorithm Type Position (Difference)
  • 42. © XPSurgery.com 2016 @kevinrutherford string[] board = new string[12];      :      : if (position[currentPlayer] > 11)   index = 0; Connascence of Value [dynamic]
  • 43. © XPSurgery.com 2016 @kevinrutherford string[] board = new string[12];      :      : if (position[currentPlayer] > 11)   index = 0; Connascence of Value [dynamic] V
  • 44. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic]
  • 45. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic] E
  • 46. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic] E E
  • 47. © XPSurgery.com 2016 @kevinrutherford Connascence of Identity [dynamic] fetch(`http://localhost:17174/salesmen/${salesmanId}`, {   method: 'put',   body: JSON.stringify({     salesmanId: salesmanId,     orderId: orderId,     commission: commission   }) })
  • 48. © XPSurgery.com 2016 @kevinrutherford Connascence of Identity [dynamic] fetch(`http://localhost:17174/salesmen/${salesmanId}`, {   method: 'put',   body: JSON.stringify({     salesmanId: salesmanId,     orderId: orderId,     commission: commission   }) }) I
  • 49. © XPSurgery.com 2016 @kevinrutherford Connascence of Timing [dynamic] xrayMachine.on() Thread.sleep(20) xrayMachine.off()
  • 50. © XPSurgery.com 2016 @kevinrutherford Connascence of Timing [dynamic] xrayMachine.on() Thread.sleep(20) xrayMachine.off() T
  • 51. © XPSurgery.com 2016 @kevinrutherford Dynamic connascence: Value Timing Execution (Difference) Identity
  • 52. © XPSurgery.com 2016 @kevinrutherford Degree Type Reach
  • 53. © XPSurgery.com 2016 @kevinrutherford 50 50 V = 2 E = 1
  • 54. © XPSurgery.com 2016 @kevinrutherford 50 50 50 V = 3 E = 3
  • 55. © XPSurgery.com 2016 @kevinrutherford 50 50 50 50 V = 4 E = 6
  • 56. © XPSurgery.com 2016 @kevinrutherford V = 5 E = 10 50 50 50 50 50
  • 57. © XPSurgery.com 2016 @kevinrutherford Type Degree Reach
  • 58. © XPSurgery.com 2016 @kevinrutherford expression ↔ expression 0 function ↔ function 1 object ↔ object 2 aggregate ↔ aggregate 3 process ↔ process 4
  • 59. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  • 60. © XPSurgery.com 2016 @kevinrutherford
  • 61. © XPSurgery.com 2016 @kevinrutherford
  • 62. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  • 63. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  • 64. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence By breaking the system into encapsulated elements
  • 65. © XPSurgery.com 2016 @kevinrutherford
  • 66. © XPSurgery.com 2016 @kevinrutherford
  • 67. © XPSurgery.com 2016 @kevinrutherford
  • 68. © XPSurgery.com 2016 @kevinrutherford
  • 69. © XPSurgery.com 2016 @kevinrutherford Ca,b = f(type, level, degree) ?
  • 70. © XPSurgery.com 2016 @kevinrutherford
  • 71. © XPSurgery.com 2016 @kevinrutherford
  • 72. © XPSurgery.com 2016 @kevinrutherford ?
  • 73. © XPSurgery.com 2016 @kevinrutherford Primitive Obsession Feature Envy Sim ulated Polym orphism Lazy Class Temporary Field Inappropriate Intim acy ShotgunSurgery Data Clump Long M ethod Large Class ??? ??? ??? ??? ??? ??? ??? RefusedBequest
  • 74. © XPSurgery.com 2016 @kevinrutherford “I'll go so far as to say that connascence [is] at the heart of modern software-engineering constructs.”
  • 75. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  • 76. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  • 77. © XPSurgery.com 2016 @kevinrutherford
  • 78. © XPSurgery.com 2016 @kevinrutherford Ca,b = f(type, level, degree)
  • 79. © XPSurgery.com 2016 @kevinrutherford 1. Break the monolith you have into meaningful encapsulation units 2. Remove the “worst” connascence among the encapsulation units 3. Find which encapsulation units have the “most” internal connascence 4. Recurse into each, returning to the top level after each one
  • 80. © XPSurgery.com 2016 @kevinrutherford
  • 81. © XPSurgery.com 2016 @kevinrutherford ? @kevinrutherford @xpsurgery http://silkandspinach.net/tag/connascence http://xpsurgery.com

Editor's Notes

  1. 1. Maths / group theory PhD 2. Encryption – mortgage transfers and Unix 3. Software house 4. Agile / XP 5. Coaching / training in s/w craftsmanship
  2. 1. There's a problem in s/w development 2. We'll look at failed solutions 3. Introduce the concept of coupling 4. Look at the properties of coupling 5. Do some calculus 6. Reconsider the problem
  3. First, the Problem...
  4. The TDD cycle Red Green Then what? Refactoring is hard No-one does it No-one knows what to do: How much? What to pick? When to stop?
  5. Now on to the failed solutions (This section may be a bit of a rant :-)
  6. People don't always know what “duplication” here means Not all duplicated text is “duplication” And duplication between Bounded Contexts is often / usually preferable to “fixing” it eg. build problems from shared library Plus, not all “duplication” is bad
  7. Ambiguous Overlapping People remember their names, but not what they mean Not clear what to DO eg. Feature Envy isn't always a problem (eg between bounded contexts)
  8. S, O describe end results – but people think they are things to DO L can be tested for, but no-one does I, D are design rules, but no-one understands what they really mean
  9. People don't know about these (People don't think about packages / namespaces / aggregates as a design tool) CCP == SRP SDP == SAP == DIP And not all dependency is bad
  10. Connascence was introduced and first examined by Meilir Page-Jones (who has the coolest moustache in CS) Connascence first appeared in this paper (Although Yourdon and Constantine kinda mention it in Structured Design in 1979)
  11. You can see in this video still that Jim is talking about connascence ...which is a CONNECTION between different software elements
  12. Connascence has a number of attributes or properties. These are my names for them, you may see others elsewhere.
  13. Let's first talk about the TYPE of the connascence
  14. Imagine we implement an object that contains a data structure based on a hash table (and for some reason we decide not to use a standard library)
  15. The get() and put() functions must agree on the hashing algorithm to be used
  16. Even if we extract the hashing algorithm to a function...
  17. … both get() and put() still need to call it, and are therefore still coupled by CoA Now, working with the person next to you, think of other examples of CoA?
  18. Consider this old-fashioned printf call in C...
  19. … there is CoP between the format string and the arguments to the call With the person next to you, think of other examples of CoP?
  20. Consider a system in which monetary amounts are represented as numbers of pence
  21. There is CoC between everything that has to calculate with those values … and also among the types of the variables and return types of the functions Now, in pairs come up with more examples of CoC
  22. NO AUDIENCE WORK HERE
  23. NO AUDIENCE WORK HERE
  24. NO AUDIENCE WORK HERE
  25. Now have the audience suggest examples
  26. Now have the audience come up with examples
  27. Now we'll cover the DEGREE of the coupling
  28. Now we'll cover the REACH of the coupling
  29. Page-Jones defines only 3 encapsulation levels But in modern programming there are more Connascence is worsened by crossing the boundary between two encapsulation units Maybe each of these is a “scope”? Maybe therefore “block” has been missed by P-J?
  30. Those are the main properties of connascence. We could also consider whether the connascence is EXPLICIT (obvious) or IMPLICIT, but Page-Jones is quite wishy-washy about this...
  31. Page-Jones gives these as guidelines for maintainability Can we turn them into an “algorithm” for refactoring?
  32. Everything depends on what we mean by these words (...and on our “definitions” of the various kinds of connascence :)
  33. We have numbers for level and degree, so let's see if we can rank the types <group exercise> Now let's list some properties of this function <call out and flipchart>
  34. Ns