Restructuring (EVO 2008)

560 views

Published on

I used this set of slides at a lecture I gave at the University of Bern.

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
560
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Restructuring (EVO 2008)

  1. 1. Restructuring Tudor Gîrba www.tudorgirba.com
  2. 2. fo rw g rin ar ee d gin en gin en ee se rin erv g re { { { { { { } { { } } actual development } } } { } } }
  3. 3. fo rw g rin ar ee d gin en gin en ee se rin erv g re { { { { { { } { { } } restructuring } } } { } } }
  4. 4. cycle ginee ring life Reen fo rw g rin ar ee d gin en gin en ee se rin erv g re { { { { { { } { { } } restructuring } } } { } } }
  5. 5. { { What? { { { { } { { } } restructuring } } } { } } }
  6. 6. Restructuring is often taken as a synonym of refactoring
  7. 7. Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior
  8. 8. Refactoring is behavior-preserving transformation
  9. 9. Restructuring is transforming a program to fit current needs
  10. 10. Why? { { What? { { { { } { { } } restructuring } } } { } } }
  11. 11. Software should be habitable
  12. 12. The secret to tidiness is to have a place for every thing Denker Markus
  13. 13. The secret to tidiness is to find the right place for every thing Denker Markus
  14. 14. If it stinks, change it Be ck Gr andma
  15. 15. How? Why? { { What? { { { { } { { } } restructuring } } } { } } }
  16. 16. Take a critical look at design
  17. 17. A God Class centralizes too much intelligence Class uses directly more than a few attributes of other classes ATFD > FEW Functional complexity of the class is very high AND GodClass WMC ! VERY HIGH Class cohesion is low TCC < ONE THIRD 006 ari nescu 2 L anza, M
  18. 18. ModelFacade from ArgoUML
  19. 19. p God Class Split u ModelFacade from ArgoUML 2 er etal 200 Demey
  20. 20. d than done Easi er sai 2 er etal 200 Demey
  21. 21. also w rap it You can 2 er etal 200 Demey
  22. 22. you do not Maybe uch it at all need to to God Class in the last version isGodClass(last) AND Harmless God Class Stable throughout the history Stability > 90% 4 Ratiu etal, 200
  23. 23. Client Provider service()
  24. 24. Client Intermediary Provider getProvider() service()
  25. 25. Client Intermediary Provider getProvider() service() this.intermediary.provider.service();
  26. 26. Provider2 service2() Client Intermediary Provider getProvider() service() Provider3 service3() this.intermediary.provider.service(); this.intermediary.provider2.service2(); this.intermediary.provider3.service3();
  27. 27. Provider2 service2() Client Intermediary Provider getProvider() service() Provider3 service3() this.intermediary.provider.service(); this.intermediary.provider2.service2(); this.intermediary.provider3.service3(); to str angers eter : D on’t talk of Dem T he Law
  28. 28. Code te Nav igation E limina Provider2 service2() Client Intermediary Provider fullService() service() Provider3 service3() this.intermediary.fullService(); 2 er etal 200 Demey
  29. 29. ge inte rfaces ad to hu t: This can le Provider2 Cavea service2() Client Intermediary Provider fullService() service() Provider3 service3() this.intermediary.fullService(); 2 er etal 200 Demey
  30. 30. Middl e Man R emove Provider2 service2() Client Provider service() Provider3 service3() this.provider.service(); this.provider2.service2(); this.provider3.service3(); Fow ler 1999
  31. 31. An Envious Method is more interested in data from a handful of other classes Method uses directly more than a few attributes of other classes ATFD > FEW Method uses far more attributes of other classes than its own AND Feature Envy LAA < ONE THIRD The used quot;foreignquot; attributes belong to very few other classes FDP ! FEW 006 ari nescu 2 L anza, M
  32. 32. ser to Data Behavi or Clo Move
  33. 33. Data Classes are dumb data holders Interface of class reveals data rather than offering services WOC < ONE THIRD AND Data Class Class reveals many attributes and is not complex 006 ari nescu 2 L anza, M
  34. 34. ser to Data Behavi or Clo Move
  35. 35. Significant Duplication 006 ari nescu 2 L anza, M
  36. 36. A A m1 m1' m3 m2 m2' 6 ne scu 200 Lanza, Mari
  37. 37. A A m3 B C B C m1 m2 m1 m2 6 ne scu 200 Lanza, Mari
  38. 38. Restructuring can also improve performance
  39. 39. BusinessObject Client BusinessSessionBean BusinessEntityBean
  40. 40. BusinessObject SessionFacade Client BusinessSessionBean BusinessEntityBean java .sun.com
  41. 41. ModelFacade from ArgoUML es are good, Not al l Facad od :) some are G
  42. 42. Trouble never comes alone Ano nymous
  43. 43. Redistribute Transform conditionals responsibilities to Polymorphism Eliminate Split up Transform Client ... Navigation Code God Class Type Checks Move Behavior Introduce Null Object Closer to Data
  44. 44. es pro blems ode co rrelat inC
  45. 45. When? How? Why? { { What? { { { { } { { } } restructuring } } } { } } }
  46. 46. Restructure all the time
  47. 47. Restructure all the time his fea sible? … hm m, is t
  48. 48. It is feasible
  49. 49. Development Maintenance
  50. 50. are evolution Softw
  51. 51. Tudor Gîrba www.tudorgirba.com creativecommons.org/licenses/by/3.0/

×