• Save
Refactoring Strategies: Beyond the Basics
Upcoming SlideShare
Loading in...5
×
 

Refactoring Strategies: Beyond the Basics

on

  • 506 views

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 sequence of refactorings to effect larger ...

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 sequence of refactorings to effect larger changes. This workshop will guide participants through hands-on exercises designed to teach three essential skills to become good at refactoring:
1. Identifying what needs refactoring: what makes code smell, confusing, or complex?
2. Identifying the end goal: what are the design options and which one will yield the best results?
3. Tracing a strategy to get the code from 1 to 2.

Statistics

Views

Total Views
506
Views on SlideShare
475
Embed Views
31

Actions

Likes
1
Downloads
0
Comments
0

2 Embeds 31

https://twitter.com 30
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Refactoring Strategies: Beyond the Basics Refactoring Strategies: Beyond the Basics Presentation Transcript

  • REFACTORING STRATEGIES: BEYOND THE BASICS Danilo Sato (@dtsato) dsato@thoughtworks.com Mariana Bravo (@marivb) mbravo@thoughtworks.com
  • 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
  • http://martinfowler.com/articles/workflowsOfRefactoring/ 8
  • EMERGENT DESIGN: JUNIT 9
  • REFACTORING STRATEGIES 10
  • EXERCISE 1 Step-by-Step 11
  • Maze 12
  • 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 fields required to decide where to move are specific to each subclass of Actor and the implementations are very different Code Smells: ●Hard to Test ●Different constructors for Pacman/Ghost ●Different 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
  • 39
  • THANK YOU For questions or suggestions: Danilo Sato (@dtsato) dsato@thoughtworks.com Mariana Bravo (@marivb) mbravo@thoughtworks.com