【发布时间】:2018-08-02 14:46:07
【问题描述】:
我正在尝试将大对象分解为较小的接口。示例:
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
}
重构之后应该是这样的:
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
{
//...
}
Visual Studio 或 Resharper 是否能够自动执行此类操作?我确实知道Extract Interface,但是对于一个大对象,从一个大列表中只检查几个属性/方法是非常痛苦的。
更新:澄清一下,我只想提取SomeService 类使用的成员。
【问题讨论】:
标签: c# visual-studio refactoring resharper automated-refactoring