Convert Interface to Abstract Class refactoring This refactoring converts interfaces into abstract classes thus helping you quickly change hierarchical dependency among a set of classes and interfaces.
Consider the following example:
Before refactoring After refactoring interface Shape
{
double Area { get ; }
void Draw ();
}
class Circle : Shape
{
private readonly int radius ;
public double Area
{
get { return Math . PI * Math . Pow ( radius , 2 ); }
}
public void Draw ()
{
//do something
}
}
abstract class Shape
{
public abstract double Area { get ; }
public abstract void Draw ();
}
class Circle : Shape
{
private readonly int radius ;
public override double Area
{
get { return Math . PI * Math . Pow ( radius , 2 ); }
}
public override void Draw ()
{
//do something
}
}
After performing this refactoring, you may want to bring some members from derived classes to the newly created abstract class. You can do it with the Pull Members Up refactoring .
To turn a suitable interface into an abstract class Select an interface in one of the following ways: In the editor, set the caret at the name of an interface. Select an interface in the Structure window . Do one of the following: Press Ctrl+Shift+R and then choose Convert Interface to Abstract Class Choose in the main menu. If no conflicts are found, Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts . Right after the refactoring has been completed, all changes that it makes anywhere, including other files, are registered as a single operation. So you can use the Undo action (Ctrl+Z ) to roll back all these changes with a single keystroke.
Last modified: 11 October 2017