1. (c) kevin rutherford 2012
describing the internal quality of software
@kevinrutherford
2. (c) kevin rutherford 2012
code smells
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphismLazy Class
Temporary Field
Inappropriate Intimacy
ShotgunSurgery
Data Clump
Long
M
ethod
Large Class
RefusedBequest
3. (c) kevin rutherford 2012
code smells
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphismLazy Class
Temporary Field
Inappropriate Intimacy
ShotgunSurgery
Data Clump
Long
M
ethod
Large Class
???
??? ???
???
???
???
???
RefusedBequest
4. (c) kevin rutherford 2012
connascence
Two software components are connascent
if a change in one would require the other to be modified
in order to maintain the overall correctness of the system.
5. (c) kevin rutherford 2012
connascence
Connascence of Name
Connascence of Type
Connascence of Meaning
Connascence of Algorithm
Connascence of Position
Connascence of Execution order
Connascence of Timing
Connascence of Value
Connascence of Identity
6. (c) kevin rutherford 2012
connascence
Connascence of Name
Connascence of Type
Connascence of Meaning
Connascence of Algorithm
Connascence of Position
Connascence of Execution order
Connascence of Timing
Connascence of Value
Connascence of Identity
refactoring should
take the code in
this direction
static code
properties
properties of
running code
7. (c) kevin rutherford 2012
connascence of name
Two components must agree on the name of something
int count;
count = 10;
public enum Deck {
SPADES, HEARTS, CLUBS, DIAMONDS
};
card = new Card(3, Deck.HEARTS);
@Override
public String toString() {
...
};
8. (c) kevin rutherford 2012
connascence of type
Two components must agree on the type of something
String var;
var = 10; // oops!
Writer out = new PrintWriter(f);
@Override
public String toString() {
...
};
9. (c) kevin rutherford 2012
connascence of meaning
Two components must agree on the interpretation of a value
String getSSN() {
if (ssnIsMissing) {
return "999999999";
} else {
return blah_blah_blah;
}
}
ssn = getSSN();
if (ssn.equals("999999999")) {
// handle missing ssn
}
switch (message.getType()) {
case 1:
return message.sendToAll();
case 2:
return message.cancel();
default:
return null;
}
10. (c) kevin rutherford 2012
connascence of meaning
Two components must agree on the interpretation of a value
String getSSN() {
if (ssnIsMissing) {
return "999999999";
} else {
return blah_blah_blah;
}
}
ssn = getSSN();
if (ssn.equals("999999999")) {
// handle missing ssn
}
switch (message.getType()) {
case 1:
return message.sendToAll();
case 2:
return message.cancel();
default:
return null;
}
11. (c) kevin rutherford 2012
connascence of algorithm
Two components must agree on a particular algorithm
@Test
public void testFingerprint() {
String actual = myObj.getFingerprint();
String expected = DigestUtils.md5Hex(myObj.name);
assertEquals(expected, actual);
}
12. (c) kevin rutherford 2012
connascence of position
Two components must be adjacent or occur in a particular order
String names[] = { "Jim", "Helen", "Jenny" };
...
System.out.println("Father: " + names[0]);
System.out.println("Mother: " + names[1]);
System.out.println("Child: " + names[2]);
Rectangle rect = new Rectangle(23.0, 15.5);
13. (c) kevin rutherford 2012
connascence of execution order
The order of execution of two components is important
Email email = new Email();
email.setSender(“joe.bloggs”);
//. . .
email.deliver();
14. (c) kevin rutherford 2012
connascence of timing
Two components must agree on the timing of execution
timeout = 200; // Milliseconds
socket.writeRequest(data);
answer = socket.readResponse(timeout);
15. (c) kevin rutherford 2012
connascence of value
The values of two components are related
class CircularBuffer {
private int myHead;
private int myTail;
// myHead == myTail => buffer empty
// myHead+1 == myTail => buffer full
}
16. (c) kevin rutherford 2012
connascence of identity
Two components must reference the same object
class Producer implements Runnable {
public static Queue myQueue;
public void run() {
myQueue.put(37);
}
}
class Consumer implements Runnable {
public void run() {
int item = Producer.myQueue.get();
processItem(item);
}
}
17. (c) kevin rutherford 2012
connascence of identity
Two components must reference the same object
class Producer implements Runnable {
public static Queue myQueue;
public void run() {
myQueue.put(37);
}
}
class Consumer implements Runnable {
public void run() {
int item = Producer.myQueue.get();
processItem(item);
}
}
also connascence
of timing
...and connascence
of type
18. (c) kevin rutherford 2012
connascence
Connascence of Name
Connascence of Type
Connascence of Meaning
Connascence of Algorithm
Connascence of Position
Connascence of Execution order
Connascence of Timing
Connascence of Value
Connascence of Identity
refactoring should
take the code in
this direction
static code
properties
properties of
running code
19. (c) kevin rutherford 2012
connascence
Two software components are connascent
if a change in one would require the other to be modified
in order to maintain the overall correctness of the system.
What Every Programmer Should Know About Object Oriented Design,
Meilir Page-Jones, Dorset House Publishing, 1996
Fundamentals of Object-Oriented Design in UML,
Meilir Page-Jones, Addison-Wesley, 1999
20. (c) kevin rutherford 2012
connascence
Two software components are connascent
if a change in one would require the other to be modified
in order to maintain the overall correctness of the system.
http://onestepback.org/articles/connascence/index.html
Jim Weirich
Connascence as a software design metric
http://blog.rubybestpractices.com/posts/gregory/056-issue-24-connascence.html
Gregory Brown
Grand unified theory of software design,
http://vimeo.com/10837903
Jim Weirich