I'm trying to break a large object into smaller interfaces. Example:
public class SomeService
{
readonly GodObject _god; // <-- Replace this with an Interface
public SomeService(GodObject god)
{
_god = god;
}
public string SomeProperty => _god.GetSomeValue();
public string SomethingElse => _god.SomethingDifferent;
}
public class GodObject
{
public string GetSomeValue()
{
// do something and return
}
public string SomethingDifferent { get; set; }
// Lots and lots more Members
}
After the refactoring it should look something like this:
public interface IPartialGodObject // <-- Extracted from GodObject
{
string GetSomeValue();
string SomethingDifferent { get; }
}
public class SomeService
{
readonly IPartialGodObject _god; // <-- Now only references the Interface
public SomeService(IPartialGodObject god)
{
_god = god;
}
public string SomeProperty => _god.GetSomeValue();
public string SomethingElse => _god.SomethingDifferent;
}
public class GodObject : IPartialGodObject
{
//...
}
Is Visual Studio or Resharper capable of doing something like this automated? I do know about Extract Interface
, but with a large object it's quite painful to check only a few Properties/Methods from a large list.
Update: To clarify, I only want the members extracted which are used by the SomeService
class.
It seems as there is no automated process to do this. What I ended up doing is the following (Resharper 2018):
Extract Interface
Select Public