SlideServe
Menu
Préférences
© SlideServe · v2026

Refactoring

priscilla-shaw avatar
14 diapositives · 254 Views · Nov 04, 2014

Refactoring. http://c2.com/cgi/wiki?ExtremeNormalForm Your classes are small and your methods are small; you've said everything OnceAndOnlyOnce and you've removed the last piece of unnecessary code.

Refactoring - slide 1
01 / 14Refactoring
1 / 17

Télécharger la présentation

Refactoring
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Refactoring

  2. http://c2.com/cgi/wiki?ExtremeNormalForm • Your classes are small and your methods are small; you've said everything OnceAndOnlyOnce and you've removed the last piece of unnecessary code. • Somewhere far away an Aikido master stands in a quiet room. He is centered.. aware.. ready for anything. • Outside a sprinter shakes out her legs and settles into the block, waiting for the crack of the gun while a cool wind arches across the track. • Softly, a bell sounds.. all of your tests have passed. • Your code is in ExtremeNormalForm.. tuned to today and poised to strike at tomorrow.

  3. Refactoring • Changes made to a program that only change its organization, not its function. • Behavior preserving program transformations.

  4. Why refactoring is important • Only defense against software decay. • Often needed to fix reusability bugs. • Lets you add patterns after you have written a program; lets you transform program into framework. • Lets you worry about generality tomorrow; just get it working today. • Necessary for beautiful software.

  5. Piecemeal Growth • The way living things grow • The way software grows • More than just addition -- transformation

  6. Duplicate code • Eliminate duplication by • making new methods • making new objects • moving methods to common superclass

  7. Long methods • Each method should do one thing. • One comment for each method. • Method should fit on the screen. • Method is all on same level of abstraction. • Method should be in right class.

  8. Move code to its right class • teacher classes add: thisClass. • teacher classLoad: (teacher classLoad + 1) • teacher addClass: thisClass

  9. Large classes • More than seven or eight variables • More than fifty methods • You probably need to break up the class • Components (Strategy, Composite, Decorator) • Inheritance

  10. Long parameter lists • If you see the same set of parameters repeated in several methods, bundle them into a new object. Create accessors to get the original parameters from the object. Change the methods to use the new object instead of the parameters. • Then figure out what other funtionality needs to move to the object.

  11. Case Statements • Use polymorphism, not case statement. • Make class hierarchy, one class for each case. • Make a method for each case statement. • Make each branch of case statement be a method in a class

  12. How to refactor • Make changes as small as possible. • Test after each change. • Many small changes are easier than one big change. • Each change makes it easier to see that more changes are needed.

  13. Refactoring browser • A better browser • Automates many refactorings - renaming, moving code, splitting • Undo • Smalllint tool helps you find places that need to be refactored.

  14. When to refactor • If a new feature seems hard to implement, refactor. • If a new feature created some ugly code, refactor. • When you can’t stand to look at your code, refactor.