First of all, I'd like to thank Resharper team for new refactorings that
I was missing from the time I used C# Refactory. Besides the fact that they
are still in EAP and are a lot buggy, it's nice they came to existance. At
this point I'd like to share some of my thoughts regarding these refactorings.
I'm not very much to refactoring ideology, but I code a lot and have some
practical observations that may be aligned or misaligned with the theory.
From my point of view, the concept behind "Extract interface/superclass"
refactorings is hierarchy manipulation. Major hierarchy changes should be
well planned by architect and probably reflected in appropriate diagram,
but there are much more small refactorings of this kind which serve momentary
needs and can be done with the help of tool such as Resharper. So, we need
to identify major requirements for manipulating type structure, split them
into elementary operations (if possible) and plan refactoring operations
with these requirements in mind. There are three most obvious operations
from the OOP/OOD point of view:
1. "Create abstraction". When you create interface or superclass you essentialy
create new abstraction (more abstract, so to say). It is pretty rare condition
to have only one class you need to abstract. Almost always you have several
classes that became too common and you want them share implementation or
semantics or both. That is first point:
-- Extract superclass/interface should manipulate multiply types --
Developer should be able to select several classes he wants to "merge" and
Resharper should provide pretty advanced interface to merge them in hierarchy
through creation of base class/interface. This can involve renaming methods,
changing signatures and otherwise preparing the merge. It's pretty complex
feature and you may consider it for IDE.
2. "Remove abstraction". Sometime types, that were initially considered similar
and has common base type become too different and base class become almost
empty and/or just useless. In this case developer wants to eliminate base
class altogether (or remove it from part of hierarchy). Existing members
should be copied into derived class and then inheritance can be removed.
This involves some smartness too, because there could be change in "virtuality"
of members, change from protected to private/internal, etc. This leads to
-- Extract superclass/interface should be reversible --
Developer should be able to point to class and issue "remove base class"
command and be able to propagate base's members to class itself. Removing
interfaces is not always just removing them from implementation list - there
could be explicit implementations that should be converted to private members.
If they are unused, they will be marked as such for the following removal.
Obviously, there can be casts to interface/base somewhere in the code. If
it is detectable, Resharper should warn.
3. "Move members". Obviously, developer may want to adjust base/derived class
members later, after "Extract superclass/interface" refactoring is completed.
There should be option to promote method to base class or interface with
appropriate change in visibility and body. As well, there should be command
to demote member from base to derived class(-es).
4. There are other things that I'd like to have in my toolbox, but they are
not so important as three above. For example, I wish to have "Copy type interface"
command, that will not copy implementation details, but instead copy public/protected/internal
interface of the type with method/property bodies filled with NotImplementedException
throws. This could work from class browser as well. Another thing is command
"Create derived type", so I can point to some class I designated as base
and then have all required abstract overrides, constructor calls (for selected
prototypes) and so on. These are just bells and whistles but they can improve
everyday coding and this is the goal of tool such as Resharper, isn't it?
Please, share your thoughts, I'd like to discuss it with Resharper team and