Refactoring I Basics and Motivation - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Refactoring I Basics and Motivation

Description:

Indirection. Breaking big objects or methods into several small ones ... Bad smell. Method - indirection. Refactoring benefits. Limitation of refactoring ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 15
Provided by: spicKa
Category:

less

Transcript and Presenter's Notes

Title: Refactoring I Basics and Motivation


1
Refactoring I - Basics and Motivation
  • Jukka Viljamaa
  • Helsinki, Seminar on programming paradigms
  • 2000. 8
  • 2004. 08. 12
  • Presented by Lee Hee-Jin

2
Contents
  • Introduction
  • Refactoring catalog
  • Basic example
  • Bad smells in code
  • Basic refactoring techniques
  • Refactoring in development process
  • Refactoring precondition - Testing
  • Benefits of refactoring
  • Limitation of refactoring
  • Critics and future work
  • Summary

3
Introduction
  • Refactoring
  • Make change of internal structure of software
    without changing observable behavior
  • Easier to understand code
  • Cheaper to modify code
  • In this paper
  • Refactoring Improving the design of existing
    code, Martin Fowler
  • Overview of refactoring
  • Method of refactoring software
  • Reason using refactoring
  • Pros and cons of refactoring

4
Refactoring catalog
  • Documentation format describing refactorings
  • 5 parts
  • Name
  • Summary
  • What this refactoring does
  • When, where to be needed
  • Motivation
  • Why refactoring should be done
  • Mechanics
  • How to carry out refactoring with step by step
    description
  • Examples
  • How refactoring is employed in real program

5
Basic example (1/2)
  • Extract method
  • Original Code
  • Void BankInterface()
  • Savemoney(moneyamount)
  • printf(Thank you )
  • printf(See you)
  • Modified code
  • Void BankInterface()
  • Savemoney(moneyamount)
  • printgoodbye()
  • Void printgoodbye()
  • printf(Thank you)
  • printf(See you)

6
Basic example (2/2)
  • Modified code
  • class Access
  • Boolean QueryUser() ..
  • int acc_num
  • .
  • if(QueryUser())
  • printf(ok)
  • class Rental
  • .
  • Move method
  • Original Code
  • class Access
  • Boolean QueryUser() ..
  • int acc_num
  • .
  • class Rental
  • Access mine new Access
  • if(mine.QueryUser())
  • printf(ok)

7
Bad smells in code
  • Term coined by Kent Beck
  • Bad smells program has
  • Bad readability
  • Duplicated logic
  • Possibility of behavior changing when code is
    modified
  • Complex conditional logic
  • What cause bad smells
  • Duplicated code
  • Too big or too small classes and methods
  • Too much or too little delegation
  • Other 20 reasons more

8
Basic refactoring techniques
  • Duplication elimination
  • Indirection
  • Breaking big objects or methods into several
    small ones
  • Delegating work to smaller units
  • Pros
  • Explaining intention and implementation
    separately
  • Use meaningful method name
  • Sharing of logic
  • Superclass logic is shared by all subclasses
  • Isolating change
  • Subclass get changes
  • Cons
  • More objects or methods to manage
  • Harder to read code with increased delegation

9
Refactoring in development process
  • Software development
  • Adding function
  • Dont change existing code, just add new function
  • Refactoring
  • When system is not well-structured, refactor it
  • Fixing a bug
  • Code review
  • Refactoring is integral part of review
  • Peer review in XP (extreme programming)
  • Concrete result of suggestion

10
Refactoring precondition - Testing
  • Existed testing code
  • Confirming same behavior as before
  • Checking any new bugs
  • Adding new testing code
  • Self-testing code
  • Each class has its own test methods
  • Fully automatic test
  • Compile system with test
  • Narrow debugging code area after last successful
    test

11
Benefits of refactoring
  • Improving design of software
  • Eliminating duplicated code makes code
    modification easy
  • Understanding code easily
  • Finding bugs easily
  • Easy debugging with fully understood code
  • Developing software more quickly
  • Bad design take more time
  • Understanding code, finding bugs, eliminating
    duplicated code

12
Limitation of refactoring
  • Accessing database
  • Changing interface
  • Especially published interface
  • Not-working code
  • Program close to deadline

13
Critics and future work
  • Not new technique any more
  • Need outstanding technique using refactoring
  • Need easy-to-use handbook
  • Little adaptability to large system
  • Need concrete tips explaining how to adopt
    refactoring

14
Summary
  • Refactoring definition
  • Basic example with refactoring method
  • Bad smell
  • Method - indirection
  • Refactoring benefits
  • Limitation of refactoring
Write a Comment
User Comments (0)
About PowerShow.com