connascence

Download Connascence

If you can't read please download the document

Upload: kevin-rutherford

Post on 16-Apr-2017

3.805 views

Category:

Technology


0 download

TRANSCRIPT

describing the internal quality of software

@kevinrutherford

code smells

Primitive Obsession

Feature Envy

Simulated Polymorphism

Lazy Class

Temporary Field

Inappropriate Intimacy

Shotgun Surgery

Data Clump

Long Method

Large Class

Refused Bequest

code smells

Primitive Obsession

Feature Envy

Simulated Polymorphism

Lazy Class

Temporary Field

Inappropriate Intimacy

Shotgun Surgery

Data Clump

Long Method

Large Class

???

???

???

???

???

???

???

Refused Bequest

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.

connascence

Connascence of NameConnascence of TypeConnascence of MeaningConnascence of AlgorithmConnascence of Position

Connascence of Execution orderConnascence of TimingConnascence of ValueConnascence of Identity

connascence

Connascence of NameConnascence of TypeConnascence of MeaningConnascence of AlgorithmConnascence of Position

Connascence of Execution orderConnascence of TimingConnascence of ValueConnascence of Identity

refactoring should
take the code in
this direction

static code
properties

properties of
running code

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() {
...
};

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() {
...
};

connascence of meaning

Two components must agree on the interpretation of a value

String getSSN() { if (ssnIsMissing) { return "999-99-9999"; } else { return blah_blah_blah; }}

ssn = getSSN();if (ssn.equals("999-99-9999")) { // handle missing ssn}

switch (message.getType()) {
case 1:
return message.sendToAll();
case 2:
return message.cancel();
default:
return null;}

connascence of meaning

Two components must agree on the interpretation of a value

String getSSN() { if (ssnIsMissing) { return "999-99-9999"; } else { return blah_blah_blah; }}

ssn = getSSN();if (ssn.equals("999-99-9999")) { // handle missing ssn}

switch (message.getType()) {
case 1:
return message.sendToAll();
case 2:
return message.cancel();
default:
return null;}

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);}

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);

connascence of execution order

The order of execution of two components is important

Email email = new Email();
email.setSender(joe.bloggs);

//. . .

email.deliver();

connascence of timing

Two components must agree on the timing of execution

timeout = 200; // Millisecondssocket.writeRequest(data);answer = socket.readResponse(timeout);

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}

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); }}

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

connascence

Connascence of NameConnascence of TypeConnascence of MeaningConnascence of AlgorithmConnascence of Position

Connascence of Execution orderConnascence of TimingConnascence of ValueConnascence of Identity

refactoring should
take the code in
this direction

static code
properties

properties of
running code

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

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.htmlGregory Brown

Grand unified theory of software design,
http://vimeo.com/10837903
Jim Weirich

Click to edit the title text format

(c) kevin rutherford 2012