This refactoring allows us to take a type and extract all the method definitions that we need, then create a new interface from them. This operation is particularly useful when going from a single implementation to using multiple implementations, such as in the example below.
To invoke this, you can use the Refactor This shortcut, Ctrl+Alt+Shift+T on Windows/Linux or ^T on macOS.
The Extract Interface dialog allows us to select any method from the existing type and control where will the interface be extracted. As such, you can create the interface in the current file/package, by default, or in a new file/package or existing ones but different than the current ones. You can also control if the methods should be exported or not, in case you do not want for external packages to be able to implement the interface.
That’s it for today. We learned how to use a new and powerful refactoring feature that will help us as the code base grows. Please let us know your feedback in the comments section below, on Twitter, or on our issue tracker.