Restructuring (EVO 2008)
-
Upload
tudor-girba -
Category
Education
-
view
1.104 -
download
0
description
Transcript of Restructuring (EVO 2008)
![Page 2: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/2.jpg)
reve
rse
engin
eerin
gforward engineering
}
{
}
{
}
{}
{
}
{
actual development }
{
}
{
}
{
}
{
![Page 3: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/3.jpg)
restructuring
reve
rse
engin
eerin
gforward engineering
}
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
![Page 4: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/4.jpg)
restructuring
reve
rse
engin
eerin
gforward engineering
}
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
Reengineering life cycle
![Page 5: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/5.jpg)
restructuring }
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
What?
![Page 6: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/6.jpg)
Restructuring is often taken as a synonym of refactoring
![Page 7: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/7.jpg)
Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior
![Page 8: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/8.jpg)
Refactoring isbehavior-preservingtransformation
![Page 9: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/9.jpg)
Restructuring is transforminga program to fit current needs
![Page 10: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/10.jpg)
restructuring }
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
What?Why?
![Page 11: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/11.jpg)
Software should behabitable
![Page 12: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/12.jpg)
![Page 13: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/13.jpg)
Markus Denker
The secret to tidiness is to have aplace for every thing
![Page 14: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/14.jpg)
Markus Denker
The secret to tidiness is to find the rightplace for every thing
![Page 15: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/15.jpg)
Grandma Beck
If it stinks, change it
![Page 16: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/16.jpg)
restructuring }
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
What?Why?How?
![Page 18: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/18.jpg)
Take a critical look at design
![Page 19: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/19.jpg)
Lanza, Marinescu 2006
A God Class centralizes too much intelligence
ATFD > FEW
Class uses directly more than a
few attributes of other classes
WMC ! VERY HIGH
Functional complexity of the
class is very high
TCC < ONE THIRD
Class cohesion is low
AND GodClass
![Page 20: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/20.jpg)
ModelFacadefrom ArgoUML
![Page 21: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/21.jpg)
ModelFacadefrom ArgoUML
Demeyer etal 2002
Split up God Class
![Page 22: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/22.jpg)
Demeyer etal 2002
Easier said than done
![Page 23: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/23.jpg)
Demeyer etal 2002
You can also wrap it
![Page 24: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/24.jpg)
Ratiu etal, 2004
AND
isGodClass(last)
God Class
in the last version
Stability > 90%
Stable throughout
the history
Harmless God Class
Maybe you do not
need to touch it at all
![Page 25: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/25.jpg)
Client
service()
Provider
![Page 26: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/26.jpg)
Client
getProvider()
Intermediary
service()
Provider
![Page 27: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/27.jpg)
Client
getProvider()
Intermediary
service()
Provider
this.intermediary.provider.service();
![Page 28: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/28.jpg)
Client
getProvider()
Intermediary
service()
Provider
this.intermediary.provider.service();
this.intermediary.provider2.service2();
this.intermediary.provider3.service3();
service2()
Provider2
service3()
Provider3
![Page 29: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/29.jpg)
Client
getProvider()
Intermediary
service()
Provider
this.intermediary.provider.service();
this.intermediary.provider2.service2();
this.intermediary.provider3.service3();
service2()
Provider2
service3()
Provider3
The Law of Demeter: Don’t talk to strangers
![Page 30: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/30.jpg)
Demeyer etal 2002
Client
fullService()
Intermediary
service()
Provider
this.intermediary.fullService();
service2()
Provider2
service3()
Provider3
Eliminate Navigation Code
![Page 31: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/31.jpg)
Demeyer etal 2002
Client
fullService()
Intermediary
service()
Provider
this.intermediary.fullService();
service2()
Provider2
service3()
Provider3
Caveat: This can lead to huge interfaces
![Page 32: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/32.jpg)
Fowler 1999
Client
service()
Provider
this.provider.service();
this.provider2.service2();
this.provider3.service3();
service2()
Provider2
service3()
Provider3
Remove Middle Man
![Page 33: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/33.jpg)
Lanza, Marinescu 2006
An Envious Method is more interestedin data from a handful of other classes
ATFD > FEW
Method uses directly more than
a few attributes of other classes
LAA < ONE THIRD
Method uses far more attributes
of other classes than its own
FDP ! FEW
The used "foreign" attributes
belong to very few other classes
AND Feature Envy
![Page 34: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/34.jpg)
![Page 35: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/35.jpg)
Move Behavior Closer to Data
![Page 36: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/36.jpg)
Lanza, Marinescu 2006
Data Classes are dumb data holders
WOC < ONE THIRD
Interface of class reveals data
rather than offering services
AND Data Class
Class reveals many attributes and is
not complex
![Page 37: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/37.jpg)
![Page 38: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/38.jpg)
Move Behavior Closer to Data
![Page 39: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/39.jpg)
Lanza, Marinescu 2006
Significant Duplication
![Page 40: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/40.jpg)
Lanza, Marinescu 2006
m2
m1
m1'
m2'
m3
AA
![Page 41: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/41.jpg)
Lanza, Marinescu 2006
m1
B C
m2
A
m1
B C
m2
A
m3
![Page 42: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/42.jpg)
Restructuring can also improve performance
![Page 43: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/43.jpg)
Client
BusinessObject
BusinessSessionBean
BusinessEntityBean
![Page 44: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/44.jpg)
java.sun.com
Client
BusinessObject
BusinessSessionBean
BusinessEntityBean
SessionFacade
![Page 45: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/45.jpg)
Not all Facades are good,
some are God :)
ModelFacadefrom ArgoUML
![Page 46: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/46.jpg)
Anonymous
Trouble never comes alone
![Page 48: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/48.jpg)
EliminateNavigation Code
Split upGod Class
Move BehaviorCloser to Data
Redistributeresponsibilities
Transform conditionalsto Polymorphism
Transform ClientType Checks
Introduce Null Object
...
![Page 49: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/49.jpg)
inCode correlates problems
![Page 51: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/51.jpg)
![Page 52: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/52.jpg)
restructuring }
{
}
{
}
{
}
{}
{
}
{
}
{}
{
}
{
What?Why?How?When?
![Page 53: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/53.jpg)
Restructure all the time
![Page 54: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/54.jpg)
Restructure all the time
… hmm, is this feasible?
![Page 55: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/55.jpg)
![Page 56: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/56.jpg)
It is feasible
![Page 57: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/57.jpg)
Development Maintenance
![Page 58: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/58.jpg)
![Page 59: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/59.jpg)
Software evolution
![Page 60: Restructuring (EVO 2008)](https://reader033.fdocuments.net/reader033/viewer/2022042713/547a4a0cb47959a9098b49a8/html5/thumbnails/60.jpg)
Tudor Gîrbawww.tudorgirba.com
creativecommons.org/licenses/by/3.0/