SYSC2101 ObjectOriented Programming and Design Laboratory - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

SYSC2101 ObjectOriented Programming and Design Laboratory

Description:

'A refactoring is a change to a program that only affects the ... Move/pull up/push down field, method (Eclipse supported!) Replace conditional with polymorphism ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 7
Provided by: donb160
Category:

less

Transcript and Presenter's Notes

Title: SYSC2101 ObjectOriented Programming and Design Laboratory


1
SYSC-2101 Object-Oriented Programming and Design
Laboratory
  • Refactoring
  • revised Jan 25th, 2004

2
What is Refactoring?
  • A refactoring is a change to a program that only
    affects the way it is organized, not its
    behavior (Ralph Johnson). Also called behavior
    preserving transformations.
  • In general, refactoring is modifying the code
    base to ensure that each thing is done once and
    only once. If something is done multiple times,
    each of those times should be replaced by a call
    to the one routine that does the thing well and
    doesn't do anything else. If closely related
    things are done at places scattered throughout
    the code base, they should be pulled together
    into a single routine. (William Grosso)

3
Why Refactor?
  • Refactoring is the process of taking an object
    design and rearranging it in various ways to make
    the design more flexible and/or reusable. (Kyle
    Brown)
  • efficiency, maintainability
  • your understanding of the code and design
    improves
  • your code improves!

4
When to Refactor?
  • whenever your code smells!
  • typically when you find duplication in your code
  • after you have finished writing code that just
    works
  • before adding new functionality
  • your code must still pass all tests after each
    refactoring!!!

5
Refactoring Examples
  • Add/remove parameter
  • Change reference to value (or the other way
    around)
  • not only a C issue! see immutable objects
  • Consolidate conditional expression, decompose
    conditional
  • Encapsulate collection, downcast, field
  • Extract class, interface (Eclipse supports it!),
    method, subclass, superclass
  • Form template method (very interesting!)
  • Introduce parameter object
  • Move/pull up/push down field, method (Eclipse
    supported!)
  • Replace conditional with polymorphism
  • Replace constructor with factory method
  • Replace inheritance with delegation

6
Resources
  • Refactoring Improving the Design of Existing
    Codeby Martin Fowler
  • http//www.refactoring.com
  • complete catalog available at
  • http//www.refactoring.com/catalog/index.html
Write a Comment
User Comments (0)
About PowerShow.com