Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Working With Legacy Code - iOS TDD Workshop
Search
Maciej Oczko
July 05, 2014
Programming
0
170
Working With Legacy Code - iOS TDD Workshop
Talk given on iOS TDD Workshop in Berlin.
Maciej Oczko
July 05, 2014
Tweet
Share
More Decks by Maciej Oczko
See All by Maciej Oczko
Dependency Injection on iOS
maciejoczko
1
120
Working with Legacy Code (Łódź)
maciejoczko
0
53
iOS TDD Workshop (Gdańsk)
maciejoczko
1
81
UICollectionView Basics and Flow Layout
maciejoczko
0
230
UICollectionView Introduction
maciejoczko
0
62
Depenedency Injection in iOS
maciejoczko
0
69
Other Decks in Programming
See All in Programming
MDN Web Docs に日本語翻訳でコントリビュートしたくなる
ohmori_yusuke
1
130
DMMを支える決済基盤の技術的負債にどう立ち向かうか / Addressing Technical Debt in Payment Infrastructure
yoshiyoshifujii
4
530
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
180
[SRE NEXT] 複雑なシステムにおけるUser Journey SLOの導入
yakenji
0
600
バイブコーディング超えてバイブデプロイ〜CloudflareMCPで実現する、未来のアプリケーションデリバリー〜
azukiazusa1
2
660
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
420
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
980
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
470
ソフトウェア設計とAI技術の活用
masuda220
PRO
23
6.4k
Jakarta EE Meets AI
ivargrimstad
0
190
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
1
220
Vibe Codingの幻想を超えて-生成AIを現場で使えるようにするまでの泥臭い話.ai
fumiyakume
18
8.8k
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Bash Introduction
62gerente
613
210k
How STYLIGHT went responsive
nonsquared
100
5.6k
Rails Girls Zürich Keynote
gr2m
95
14k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Git: the NoSQL Database
bkeepers
PRO
431
65k
Being A Developer After 40
akosma
90
590k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Building Applications with DynamoDB
mza
95
6.5k
Code Reviewing Like a Champion
maltzj
524
40k
Transcript
Working With Code Legacy @maciejoczko #tddberlin
Code is you didn’t write this morning (yet). What is
LegacyCode? Code is legacy code as soon as it's written. @maciejoczko #tddberlin
Code is legacy code as soon as it's written. Michael
Feathers, Working Effectively with Legacy Code What is LegacyCode? Code is you didn’t write this morning (yet). @maciejoczko #tddberlin
Code without tests* Inherited code Poorly designed code Too complicated
code Illegible code *Michael Feathers What is LegacyCode? Code is legacy code as soon as it's written. Michael Feathers, Working Effectively with Legacy Code @maciejoczko #tddberlin
Testing scenario #1 Task @maciejoczko #tddberlin
How to approach it? Identify change points Find an inflection
point Cover the Make changes Refactor the covered code inflection point @maciejoczko #tddberlin
B A D C E inflection point @maciejoczko #tddberlin
Violation of Single Responsibility Principle Violation of Open-Closed Principle inflection
point @maciejoczko #tddberlin
inflection point Covering external dependencies Break @maciejoczko #tddberlin
inflection point Covering external dependencies internal dependencies Break Break @maciejoczko
#tddberlin
inflection point Covering external dependencies internal dependencies Write tests Break
Break @maciejoczko #tddberlin
inflection point Covering external dependencies internal dependencies Write tests Break
Break @maciejoczko #tddberlin
- (NSUInteger)calculatePrice { ... StockAnalyzer *analyzer = [[StockAnalyzer alloc] init];
... } - (id)initWithAnalyzer:(id <AnalyzerProtocol>)analyzer { self = [super init]; if (self) { _analyzer = analyzer; } return self; } external dependencies Break @maciejoczko #tddberlin
external dependencies Break internal dependencies Write tests Break inflection point
Covering @maciejoczko #tddberlin
- (CGSize)calculateSize { ... UIScreen *screen = [UIScreen mainScreen]; ...
} - (CGSize)calculateSize { ... UIScreen *screen = [self screen]; ... } - (UIScreen *)screen { return [UIScreen mainScreen]; } Break internal dependencies @maciejoczko #tddberlin
external dependencies Break internal dependencies Write tests Break inflection point
Covering @maciejoczko #tddberlin
Write tests @maciejoczko #tddberlin
Make changes @maciejoczko #tddberlin
Testing scenario #2 Task @maciejoczko #tddberlin
When to Refactor? Too wide class responsibility Duplicated code Not
readable code Too many method arguments (more than 2) Method has more than 20 lines Class has more than 150-200 lines @maciejoczko #tddberlin
Keep in mind Composition over inheritance Avoid singletons Isolate dependencies
Inject dependencies @maciejoczko #tddberlin
Thanks! @maciejoczko #tddberlin