Download - Ddc2011 효과적으로레거시코드다루기
![Page 1: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/1.jpg)
효과적으로 레거시 코드 다루기
서비스플랫폼개발팀백명석
![Page 2: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/2.jpg)
Contents
The Way We Work
The Way We Have To Work
What is Legacy Code
Working Effectively with Legacy Code
Strategy
Case Study
![Page 3: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/3.jpg)
The Way We Work
Quick & Dirty
Slow Down
Alternative
Landing Time
Cycle(3 Years)
![Page 4: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/4.jpg)
The Way We Have To Do
Quick & Clean
But We Already Have ...
Work Effectively with Legacy Code
Build Your Value
![Page 5: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/5.jpg)
What is Legacy Code
Codes Without Tests
Hard to get tested
New Code : Legacy = 1 : 100(1,000)
Have to make decoupling design changes
No safety net
Catch-22
![Page 6: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/6.jpg)
Working Effectively with Legacy Code
"Find some small part of legacy codes you can test without making big changes.
Then use those tests to extends the design changes more safely."
![Page 7: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/7.jpg)
Strategy
Don’t Start Big Project
Wait Until New Feature is Needed
Always Prefer Test First
![Page 8: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/8.jpg)
Don’t Start Big Project
New Project for Refactoring or Testing
Everything is fine at start
Doing New design
Cause Double-duty
Impossible to replace the old system
![Page 9: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/9.jpg)
Wait Until New Feature is Needed
Change little bit of design
Add a few tests in the affected area
Eventually spread the test through out the legacy code
Not all but important/vital bits are get tested
![Page 10: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/10.jpg)
For all new code you write
write test first
Option either modify or add a new module
write a new module with TFD
Always Prefer Test First
![Page 11: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/11.jpg)
One More Automation by Tools
![Page 12: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/12.jpg)
Case Study
Extract Method
Sprout Method
Characterization Test
Subclass and Override Method
Extract Method Object
![Page 13: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/13.jpg)
Have to Understand but Function is Too Big
Function Size(Screenful)
Function Should Do One Thing
Extract Major Sections into Function
Extract Different levels of abstract
![Page 14: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/14.jpg)
Extract Different Levels of Abstraction
Extract Till You Drop
Until simply restates the code without changing abstraction level
Most basic refactoring technique
Safe with tool support
![Page 15: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/15.jpg)
Extract Method Example
Forbidden Keyword Check Controller
![Page 16: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/16.jpg)
As a Result
Composed Method Pattern
To Paragraphs
All class’s methods are less than 4 lines
{} in if, while stmt removed
Comment removed
Easy to read in top-down way
![Page 17: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/17.jpg)
Before
![Page 18: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/18.jpg)
After
![Page 19: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/19.jpg)
Have to Change But Not Enough Time
No Time to Break Dependency and Add Tests
TDD for new feature
Solutions
Sprout method / Sprout class
Wrap method / Wrap class
![Page 20: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/20.jpg)
Sprout Method
You Need to Add a Feature to a System
Can be formulated completely as new code
Write the code in a new method
Call it from the places where the new functionality needs to be
![Page 21: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/21.jpg)
Sprout Method Structure
![Page 22: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/22.jpg)
Steps
Identify where you need to make your code change.
Write down a call for a new method then comment it out.
Develop the sprout method using TDD
Remove the comment to enable the call.
![Page 23: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/23.jpg)
Sprout Method Example
Add Synchronized Token Pattern to EditArticleController
![Page 24: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/24.jpg)
Test
![Page 25: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/25.jpg)
Production
![Page 26: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/26.jpg)
Need to Make Change But Don’t Know What Tests to Write
Need to Know What the SW Supposed To Do
Write Tests Based on Those Ideas
Dig up Old Requirements Documents and Project Memos ???
![Page 27: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/27.jpg)
Characterization Test
What the systems does is more important than what it is supposed to do.
We want preserve behavior
Test that characterizes the actual behavior of a piece of code.
![Page 28: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/28.jpg)
Steps
Write an assertion that you know will fail
Let the failure tell you what the behavior is
Change the test so that it expects the behavior that the code produces
![Page 29: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/29.jpg)
Characterization Test Example
Xml Request String Factory
![Page 30: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/30.jpg)
Remove Unwanted Dependency
Too complex or impossible to mock out
Prefer no mocking in terms of better design
![Page 31: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/31.jpg)
Subclass and Override Method
A core technique for breaking dependencies in OOP
Use inheritance in the context of a test
to nullify behavior that you don’t care about
to get access to behavior that you do care about
![Page 32: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/32.jpg)
Subclass and Override Method Example
Static Function
global variable like as singleton
![Page 33: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/33.jpg)
Big function hides classes
Big function
Variables & Arguments
Functional Sections Inside Indents
Class
Set of Variables
Set of Functions Operate on These Variables
![Page 34: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/34.jpg)
Extract Method Object
Steps
Extract Method(invoke)
Create New Inner Class
Convert Arg. to Field
Convert Local Var. to Field
![Page 35: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/35.jpg)
Extract Method Object
Steps
Move Initialization Logic to constructor
Extract Methods Till You Drop
Move Type to New File
Rename class / method
Method Ordering(Top-Down, To-paragraph)
![Page 36: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/36.jpg)
Extract Method Object Example
ArticleController#buildRelatedContents
![Page 37: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/37.jpg)
As a Result
Large Ugly Tangled Function
Extracted into More than 1 classes
Which are Ready to Refactor
![Page 38: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/38.jpg)
Before
![Page 39: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/39.jpg)
After
![Page 40: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/40.jpg)
Etc.
Adding New Feature
TDD / Programming by Difference
Reuse What
Study Test
2 Way TDD
![Page 41: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/41.jpg)
ReferenceWorking Effectively with Legacy Code
http://build.gaia.daum.net/wiki/study:working_effectively_with_legacy_code
Clean Coders
http://build.gaia.daum.net/wiki/study:clean-coders-codecasts
TDD by Kent beck
http://build.gaia.daum.net/wiki/study:tyrant
토비의 스프링 3
![Page 42: Ddc2011 효과적으로레거시코드다루기](https://reader031.vdocuments.site/reader031/viewer/2022022413/589f36d31a28ab4d568b7239/html5/thumbnails/42.jpg)
Q & A