开发者

extract superclass from multiple classes and derive from it

开发者 https://www.devze.com 2023-04-12 15:15 出处:网络
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, b

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?


  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消