1 / 83

Refactoring hacked

Learn about refactoring and its importance in improving code quality and readability. Discover when and how to refactor for maximum effectiveness.

ksinclair
Download Presentation

Refactoring hacked

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Refactoringhacked Sebastian Malaca

  2. Whoam I? • Fanatic of the OOP and the Code’s Quality • Blogger • Speaker • Trainer and consultant • Software Developer at Luxoft • @SebastianMalaca • letstalkaboutjava.blogspot.com www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  3. What's in the Menu? • What is Refactoring? • Is it worth the effort? • What you should know about Refactoring? • How? www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  4. WhatisRefactoring? www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  5. WhatisRefactoring? SMALL CHANGES www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  6. WhatisRefactoring? NO CHANGES!!! SMALL CHANGES www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  7. WhatisRefactoring? NO CHANGES!!! SMALL CHANGES READABILITY www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  8. Is it worth the effort? www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  9. Is it worth the effort? • It's expensive-> Small changes -> Habit www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  10. Is it worth the effort? • It's NOT expensive • Only for big projects -> Success -> Long life www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  11. Is it worth the effort? • It's NOT expensive • NOT only for big projects • Must have in big projects -> Come and go -> no author -> readability www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  12. Refactoring vs. Redesign

  13. Refactoring vs. Redesign Refactoring Redesign Improvements and Extensions Complexchanges Dependencies Planning • Readability and Understanding • Atomicchanges • Class as a starting point • Ad hoc www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  14. Staysafe!

  15. Staysafe! No tests, no fun! www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  16. Staysafe! No tests, no fun! ExperimentationorProfessionalism? www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  17. Staysafe! No tests, no fun! ExperimentationorProfessionalism? Doubtsvs. Certainty www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  18. You have to know when to stop!

  19. Youhave to know when to stop Refactoring isfun www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  20. Youhave to know when to stop Refactoring isfun Refactoring – neverending story www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  21. Youhave to know when to stop Refactoring isfun Refactoring – neverending story Boundaries and Values www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  22. Youhave to know when to stop Refactoring isfun Refactoring – neverending story Boundaries and Values Perfection! www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  23. Youhave to know when to stop Refactoring isfun Refactoring – neverending story Boundaries and Values Perfection! Software with the users vs. Ideal software www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  24. Youhave to know when to stop Refactoring isfun Refactoring – neverending story Boundaries and Values Perfection! Software with the users vs. Ideal software www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  25. www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  26. It’sworth to knowpatterns

  27. It’sworth to knowpatterns www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  28. Gimmethename! www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  29. Let's take a look at the code!

  30. There’sonly a small condition…

  31. Less dependencies • privateTestsRepositorytestsRepository;privateCodeBaseRepositorycodeBaseRepository;public voidapply(ClassCodecode, Developer developer) {if(codeBaseRepository.contains(code) && testsRepository.testsExistFor(code)) {startRefactoringOf(code, developer); }} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  32. Less dependencies • privateTestsRepositorytestsRepository;privateCodeBaseRepositorycodeBaseRepository;public voidapply(ClassCodecode, Developer developer) {if(codeBaseRepository.contains(code) && testsRepository.testsExistFor(code)) {startRefactoringOf(code, developer); }} • private RefactoringPossiblePredicate refactoringPossiblePredicate;public void apply(ClassCode code) {if (refactoringPossiblePredicate.apply(code)) { startRefactoringOf(code, developer); }} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  33. The sizematters! privateTestsRepositorytestsRepository;public voidapply(ClassCodecode, Developer developer) {if(testsRepository.testsExistFor(code) &&developer.canModify(code) && (code.isComplex() || code.isUnreadable())) {startRefactoringOf(code); }} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  34. The sizematters! privateTestsRepositorytestsRepository;public voidapply(ClassCodecode, Developer developer) {if(testsRepository.testsExistFor(code) &&developer.canModify(code) && (code.isComplex() || code.isUnreadable())) {startRefactoringOf(code); }} Whenobjectknows… privateTestsRepositorytestsRepository;public voidapply(ClassCodecode, Developer developer) {if(testsRepository.testsExistFor(code) &&developer.canModify(code) &&code.canBeImproved()) {startRefactoringOf(code); }} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  35. The sizematters! privateTestsRepositorytestsRepository;public voidapply(ClassCodecode, Developer developer) {if(testsRepository.testsExistFor(code) &&developer.canModify(code) && (code.isComplex() || code.isUnreadable())) {startRefactoringOf(code); }} privateTestsRepositorytestsRepository;public voidapply(ClassCodecode, Developer developer) {if(testsRepository.testsExistFor(code) &&developer.canModify(code) &&code.canBeImproved()) {startRefactoringOf(code); }} privateCanStartRefactoringPredicatecanStartRefactoringPredicate;public voidapply(ClassCodecode, Developer developer) {if(canStartRefactoringPredicate.apply(code, developer)) {startRefactoringOf(code); }} Single ResponsibilityPrinciple www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  36. Or And?

  37. Or if(code.isComplexOrUnreadable()) {doRefactoring(code);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  38. Or if(code.isComplexOrUnreadable()) {doRefactoring(code);} if(code.canBeImproved()) {doRefactoring(code);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  39. And if (isRefactoringPossibleAndJustifiedPredicate.apply(code, developer)) { doRefactoring(code);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  40. And if (isRefactoringPossibleAndJustifiedPredicate.apply(code, developer)) { doRefactoring(code);} if (canStartRefactoringPredicate.apply(code, developer)) { doRefactoring(code);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  41. Method’snamemakes a difference

  42. Method’snamemakes a difference refactoring.setState(IN_PROGRESS); refactoring.setState(VERIFIED); refactoring.setState(DONE); www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  43. Method’snamemakes a difference refactoring.setState(IN_PROGRESS); refactoring.setState(VERIFIED); refactoring.setState(DONE); refactoring.start();refactoring.accepted();refactoring.applied(); www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  44. Don’t show too much

  45. Law of Demeter public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getMethodByName(refactoring.getScope()).getCondition();RefactoringApplier.applyRefactoringFor(condition, refactoring);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  46. Law of Demeter public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getMethodByName(refactoring.getScope()).getCondition();RefactoringApplier.applyRefactoringFor(condition, refactoring);} public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getConditionOf(refactoring.getScope());RefactoringApplier.applyRefactoringFor(condition, refactoring);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  47. Tell, don’tAsk public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getMethodByName(refactoring.getScope()).getCondition();RefactoringApplier.applyRefactoringFor(condition, refactoring);} public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getConditionOf(refactoring.getScope());RefactoringApplier.applyRefactoringFor(condition, refactoring);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  48. Tell, don’tAsk public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getMethodByName(refactoring.getScope()).getCondition();RefactoringApplier.applyRefactoringFor(condition, refactoring);} public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getConditionOf(refactoring.getScope());RefactoringApplier.applyRefactoringFor(condition, refactoring);} public voidapply(ClassCodecode, Refactoringrefactoring) {code.apply(refactoring);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  49. Tell, don’tAsk public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getMethodByName(refactoring.getScope()).getCondition();RefactoringApplier.applyRefactoringFor(condition, refactoring);} Askingmanyobjects… public voidapply(ClassCodecode, Refactoringrefactoring) {Conditioncondition = code.getConditionOf(refactoring.getScope());RefactoringApplier.applyRefactoringFor(condition, refactoring);} public voidapply(ClassCodecode, Refactoringrefactoring) {code.apply(refactoring);} www.luxoft.com, @SebastianMalaca, letstalkaboutjava.blogspot.com

  50. Too much is… too much

More Related