1 c# oop design-patterns adapter interface-segregation-principle
假设我有一些胖接口,无法更改.而且我还有一些客户端类只想使用胖接口中的少数方法.如何针对这种情况实现适配器模式,实现接口隔离原则?
这很容易.你需要这样的东西:
interface IAmFat
{
void Method1();
void Method2();
...
void MethodN();
}
interface IAmSegregated
{
void Method1();
}
class FatAdapter : IAmSegregated
{
private readonly IAmFat fat;
public FatAdapter(IAmFat fat)
{
this.fat = fat;
}
void IAmSegregated.Method1()
{
this.fat.Method1();
}
}
Run Code Online (Sandbox Code Playgroud)