可以说我有下面的一组接口....如何重构胖界面?
public interface IStart
{
void M1();
bool IsWorking { get; }
}
public interface IStartStop : IStart
{
void M2();
event EventHandler DoM1;
event EventHandler DoM2;
}
public interface IPreferencesReader : IStartStop, IDisposable
{
string CustomColumnDefinition {get;}
bool UsePricelevelDetection {get;}
void InitializePreferences();
}
现在,如果我要实现我的IPreferencesReader类会是什么样子下面。这是一个胖接口的例子,其中我必须提供实现我可能不需要的方法。
public class PreferencesReaderBase : IPreferencesReader
{
public void M1()
{
throw new NotImplementedException();
}
public bool IsWorking
{
get { throw new NotImplementedException(); }
}
public void M2()
{
throw new NotImplementedException();
}
public event EventHandler DoM1;
public event EventHandler DoM2;
public void Dispose()
{
throw new NotImplementedException();
}
public string CustomColumnDefinition
{
get { throw new NotImplementedException(); }
}
public bool UsePricelevelDetection
{
get { throw new NotImplementedException(); }
}
public void InitializePreferences()
{
DoSomeInitialization();
}
}
我可以应用这种情况下的任何模式,以重构它吗?
编辑:我不能没有这个层次,因为在不能删除任何接口。
感谢您的关注。
我认为你的IPreferencesReader做了太多事情:CustomColumnDefinition听起来并不像读取偏好那样,例如,它听起来应该是在子类上。 – 2010-06-24 14:28:56