Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Jason Gorman
© www.parlezuml.com
The Professional’s Dilemma
expendability
time
© www.parlezuml.com
What Is Refuctoring?
• Refuctoring is the process of taking a well-
designed piece of code and, through a
series of small, reversible changes,
making it completely unmaintainable by
anybody except yourself.
• Comprehensive regression testing
guarantees that nobody will be any the
wiser.
© www.parlezuml.com
Dilemma Solved – With
Refuctoring!
expendability
Indefinitely
sustainable income
time
© www.parlezuml.com
Code “Smiles”
• Common sense naming conventions
• Cohesive and loosely coupled modules
• Elegant abstractions
• Lack of duplication
• A close resemblance to the application
domain
© www.parlezuml.com
The Refuctoring Process
3. Call your
1. Make a single
accountant with
refuctoring
the good news
© www.parlezuml.com
Common Refuctorings
© www.parlezuml.com
Code Smile – Common Sense
Naming Conventions
class Account {
class Account {
© www.parlezuml.com
Refuctoring #1 – Pig Latin
public void w ithdraw(float amount) { refuctored! public void ithdrawway(oatflay amountw ay) {
public void w ithdraw(float amount) { public void ithdrawway(oatflay amountw ay) {
balance -= amount; alancebay -= amountw ay;
balance -= amount; alancebay -= amountw ay;
} }
} }
© www.parlezuml.com
Code Smile – Simple, Easy-to-
follow Code
payer.w ithdraw(amount);
payer.w ithdraw(amount);
payee.deposit(amount);
payee.deposit(amount);
}
}
© www.parlezuml.com
public void executeTransaction() {
public void executeTransaction() {
this.callExecuteTransaction();
this.callExecuteTransaction();
Refuctoring #2 –
}
}
Treasure Hunt
helper.doExecute();
helper.doExecute();
}
}
.........
.........
* 1
Book Library
Member
© www.parlezuml.com
Refuctoring #3 – Unique Modeling Language
refuctored!
© www.parlezuml.com
Code Smile – Clutter-free Code
© www.parlezuml.com
/*
/*
Bleeding 13/9/05
13/9/05
12:33:14
12:33:14
Accidentally deleted a line then used "undo" to
Accidentally deleted a line then used "undo" to
bring it back again
bring it back again
*/
*/
for (int number = 1; number <= 12; number++) {
for (int number = 1; number <= 12; number++) {
/*
/*
get the System's output stream to print the follow ing text:
get the System's output stream to print the follow ing text:
// use the { character to let the compiler know where the for loop ends
// use the { character to let the compiler know where the for loop ends
} © www.parlezuml.com
}
Code Smile – No Redundant Code
© www.parlezuml.com
Refuctoring # 5 – Rainy Day Module
class SpareCode {
class SpareCode {
spareInteger = 1;
spareInteger = 1;
if( youNeverKnow ) {
if( youNeverKnow ) {
spareInteger++;
spareInteger++;
}
}
System.out.println( luckyString);
System.out.println( luckyString);
}
}
}
}
refuctored!
© www.parlezuml.com
Code Smile – Manageable
Modules
* 1
*
*
* 1 * 1
*
*
© www.parlezuml.com
Refuctoring # 6 – Module Gravity Well
Application
doStuff()
openWindows()
connectToDatabase()
blah()
etc()
kitchenSink()
ev ery Man()
andHisDog()
inForAPenny()
any PortInAStorm()
makeHayWhileTheSunShines()
aRollingStoneGathersNoMoss()
didY ouSeeDoctorWhoLastNight()
iAmTheWalrus()
areWeThereY et()
method()
madness()
wakaJawaka()
aHooliHay liHah()
andAPartridgeInAPairTree()
twelv eMonkeys() refuctored!
twelv eMoreMonkeys()
meToo()
meThree()
andThenThereWereNone()
andBaby MakesThree()
captainScarlettDumDeeDumDeeDum()
itAintHalfHotMum()
dontPutYourDaughterOnTheStageMrsWorthington()
foo()
yung()
insert()
remove()
doTheHokeyCokey()
© www.parlezuml.com
Refuctoring Metrics
© www.parlezuml.com
Further Reading
• Refuctoring To Anti-Patterns. John Q. Clockwatcher
• Mortgage-driven Development. Keith Bank-Account
• Timesheet-oriented Architecture. Jill Tax-Haven
© www.parlezuml.com
www.parlezuml.com
© www.parlezuml.com