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 ma开发者_如何学运维nually then derive from this base class and search for same members in every class I want to be derived?
- Run all of your unit tests and see that they pass
- Extract the base class from one of your classes. Call it
BaseClass
or something - Run all of your unit tests ...
- Extract the base class from another of your classes. Call it
BaseClass2
or something - Run all of your unit tests...
- Compare
BaseClass
andBaseClass2
line for line. If they're not identical, then refactor them to make them identical. - Frequently running all of your unit tests...
- Once they're identical, change all references to
BaseClass2
toBaseClass
- Remove the unused
BaseClass2
- 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.
精彩评论