Published on February 25, 2014
REFACTORING STRATEGIES: BEYOND THE BASICS Danilo Sato (@dtsato) email@example.com Mariana Bravo (@marivb) firstname.lastname@example.org
WHAT WE ARE DOING TODAY PacMan Other 2
AGENDA ▫︎ ▫︎Introduction Exercise 1: Step-by-Step ▫︎ Exercise 2: On Your Own ▫︎ Form Pairs and Setup 3
FORM PAIRS & SETUP ▫︎ ... if you have internet connection: $ git clone -b workshop_start https://github.com/dtsato/ pacman_workshop.git pacman_workshop ▫︎ ... if you have local network: $ git clone git@<IP>:/tmp/workshop pacman_workshop IP: X.X.X.X Password: **** pen ▫︎Oun allproject in IDE (Eclipse or IntelliJ) R tests ▫︎ 4
INTRODUCTION Concepts and Examples 5
REFACTORING "Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior" 6
CODE SMELL "Code smell is a symptom in the source code that possibly indicates a deeper problem with the system" 7
EMERGENT DESIGN: JUNIT 9
REFACTORING STRATEGIES 10
EXERCISE 1 Step-by-Step 11
Tile Current Tile determined by Actor’s center 13
X Y [0, 6] TileCoordinate 14
WHAT IS THE PROBLEM? coordinates are exposed and used throughout the codebase as int x, y Tile Code smells: ● Primitive Obsession ● Data Clump 15
OBJECTIVES Finish the refactoring to use a new TileCoordinate class Focus on Maze class Encapsulate int x, y inside the TileCoordinate class 16
Refactoring Strategy STEP-BY-STEP Exercise_1_instructions.html
DISCUSSION What have you learned? 18
R LIMITED E D 19
CONTINUOUS DELIVERY 20
ALWAYS RELEASABLE 21
EXPAND-CONTRACT (A) Client A Subject oldWay() Client B 22
EXPAND-CONTRACT (A) Client A Client B Subject oldWay() newWay() 23
EXPAND-CONTRACT (A) Client A Client B Subject oldWay() newWay() 24
EXPAND-CONTRACT (A) Client A Client B Subject newWay() Inline Method 25
EXPAND-CONTRACT (B) Client A Subject oldWay() Client B 26
EXPAND-CONTRACT (B) Client A Client B Subject oldWay() newWay() 27
EXPAND-CONTRACT (B) Client A Client B Subject oldWay() newWay() 28
EXPAND-CONTRACT (B) Client A Client B Subject oldWay() newWay() 29
EXPAND-CONTRACT (B) Subject Client A Client B newWay() Safe Delete 30
EXERCISE 2 Your own Refactoring Strategy 31
Actor center, direction + collidesWith(Actor) + advance(millis) + getNextTile(current) Ghost Pacman 32
WHAT IS THE PROBLEM? The ﬁelds required to decide where to move are speciﬁc to each subclass of Actor and the implementations are very diﬀerent Code Smells: ●Hard to Test ●Diﬀerent constructors for Pacman/Ghost ●Diﬀerent implementations 33
Actor MovementStrategy + getNextTile() Ghost Strategy Pacman Strategy 34
OBJECTIVES Extract a new interface MovementStrategy to decide what is the next Tile Implement this interface twice: PacmanStrategy and GhostStrategy Replace “Template Method” with composition in Actor class 35
REFACTORING STRATEGY ▫︎Keep coverage high and tests passing! ▫︎ Now it’s your turn! ▫︎Decide your strategy ▫︎Implement! ▫︎ Explore the code 36
DISCUSSION What have you learned? 37
REFERENCES ▫︎ Refactoring: Improving the design of existing code ▫︎ Martin Fowler, Kent Beck, et.al ▫︎ Refactoring to Patterns ▫︎ Joshua Kerievsky ▫︎ Extreme Programming Explained 2nd Edition ▫︎ Kent Beck, Cynthia Andres ▫︎ The Mikado Method ▫︎ Ola Ellnestam, Daniel Brolund ▫︎ Domain Driven Design: Tackling Complexity in the Heart of Software ▫︎ Eric Evans 38
THANK YOU For questions or suggestions: Danilo Sato (@dtsato) email@example.com Mariana Bravo (@marivb) firstname.lastname@example.org
README.md Refactoring Strategies: Beyond the Basics. Code repository used for the "Refactoring Strategies: Beyong the Basics" workshop. Presented at: Agile ...
Refactoring is a fundamental practice for an agile developer. Each refactoring is a small and isolated activity, but the value comes when you perform a ...
Sessions 3 & 4 – Refactoring Strategies: Beyond the Basics & Workshop – Danilo Sato – Video June 6, 2016. Sessions 3-4 – Refactoring Strategies ...
Uploads from CoderConference ... Distributed Caching with JCache and Beyond Featuring Terry ... Refactoring Strategies: Beyond the Basics with Danilo ...
... Danilo Sato - Refactoring Strategies - Beyond the Basics.mp3. 16/08/2014 | 01:27:57. Devnexus 2014 - Craig Walls - Whats new in Spring.mp3 ...
Make It Great: Refactoring That’s Smart and Satisfying. Busy Developer’s Intro to NodeJS. New Linting Rules. ... Refactoring Strategies: Beyond the Basics.
Thank you @dtsato for Refactoring Strategies:Beyond the Basics workshop at this year's #chicoder2016! See it here http:// bit.ly/29uHees .
My name is Martin Fowler: ... Refactoring. Refactoring has ... JSON documents can often be made easier by encapsulating a combination of loading strategies ...