JetBrains Rider 2018.2 Help

Extract Interface refactoring

This refactoring helps create a new interface based on a selected type. JetBrains Rider suggests to choose members to be transferred to the new interface. After extraction, the original type is updated to implement the new interface.
If the current type already implements any interfaces, these interfaces can also be extracted into the new interface.

In the example below, the Color property and the Draw method of the Circle class are extracted to create a new interface:

Before refactoring

After refactoring

class Circle { public Point Center { get; private set; } public Color Color { get; private set; } public int Radius { get; private set; } public void Draw() { // draw... } }

interface IShape { Color Color { get; } void Draw(); } class Circle : IShape { public Point Center { get; private set; } public Color Color { get; private set; } public int Radius { get; private set; } public void Draw() { // draw... } }

To extract an interface from a type

  1. Select a type in one of the following ways:
    • In the editor, set the caret at the name of a type.

    • Select a type in the Structure window.

  2. Do one of the following:
    • Press Ctrl+Shift+R and then choose Extract Interface

    • Choose Refactor | Extract Interface in the main menu.

    The Extract Interface dialog will open.
  3. Specify a name for the interface and where it should be placed - in a new file or in the same file as the original type.

  4. Select members that you want to transfer to the new interface. The list of members can contain:
    • Members of the current type

    • Members of base types that the selected type currently inherits/implements

    • Interfaces that the selected type currently implements

  5. To quickly select all public members, click Select Public icon select public (Alt+P).

  6. If you have selected members that reference other members, the latter are highlighted with red. Click Dependent to resolve the conflict, i.e. to select any members that depend on the currently selected members.

  7. To apply the refactoring, click Next.

  8. If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
JetBrains Rider. Extracting interface from a class
Last modified: 21 December 2018

See Also