Extract interface from **usage** in current context (is it possible?)

I know that you can extract an interface when in a class. What I would really like is a way to extract an interface from the usage of a variable (or property) in the context of its use.

For example,

void DoSomething(MyForm f) {      f.ValueChanged(10); } class MyForm : Form {      public void ValueChanged(int newValue) {...}      ... }

would become

void DoSomething(IView f) {      f.ValueChanged(10); } interface IView {      void ValueChanged(int newValue); }

class MyForm : Form, IView {      public void ValueChanged(int newValue) {...}      ... }

So, within the context of the `DoSomething` method, the `f` variable is only calling the `ValueChanged` method, so extracting an interface from that usage would only pull out that method from the `MyForm` class.

If we were using a property instead, the usage would incorporate all method calls on that property.

This would be a particularly useful refactoring for MVP/MVVM/MVC patterns because I could code to the Form until I was happy with the interface, then I could extract only those methods used in the Presenter/Controller and ignore all of the other methods in the Form/View.

So, does this exist somehow already? If not, I request that it be added.

1 comment
Comment actions Permalink

Hello Pat,

Thanks for this one. Unfortunately, it is not possible fopr now, so I've logged this request in YouTrack here: http://youtrack.jetbrains.com/issue/RSRP-383015.

Thank you for the suggestion!


Please sign in to leave a comment.