Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract superclass from multiple classes and derive from it

I want to refactor multiple classes that I think should derive from one base class.

How to properly accomplish this refactoring using ReSharper 6 ? I can extract superclass from one of the classes, but what next? Do I have to manually then derive from this base class and search for same members in every class I want to be derived?

like image 364
Alex Burtsev Avatar asked Oct 13 '11 14:10

Alex Burtsev


1 Answers

  1. Run all of your unit tests and see that they pass
  2. Extract the base class from one of your classes. Call it BaseClass or something
  3. Run all of your unit tests ...
  4. Extract the base class from another of your classes. Call it BaseClass2 or something
  5. Run all of your unit tests...
  6. Compare BaseClass and BaseClass2 line for line. If they're not identical, then refactor them to make them identical.
  7. Frequently running all of your unit tests...
  8. Once they're identical, change all references to BaseClass2 to BaseClass
  9. Remove the unused BaseClass2
  10. Run your unit tests...

Repeat as required.

Note this is pretty much the same procedure to use when you find some common code you feel should be all a single method.

like image 88
John Saunders Avatar answered Oct 19 '22 10:10

John Saunders