다음과 같은 경우가 발생하는 시스템을 설계하고 있습니다. 구현마다 동작이 다른 f1() 메서드가 있습니다. 모든 구현에 대해 동작이 동일한 f2() 메서드가 있습니다.디자인 리팩토링
interface I1
{
//Behaviour will vary across implementations
void f1();
//Same behaviour for all implementations
void f2();
}
abstract class C
{
//Implemented in the Base class
void f2()
{
}
}
public class C1:C,I1
{
//Implemented interface method
public f1()
{
}
}
public class C2:C,I1
{
//Implemented interface method
public f1()
{
}
}
는 설계가 올 수 있습니다 :
나는 다음과 같은 설계했다? 아무도이 sceanario에서 적절한 디자인을 제안 할 수 있습니까? 다음과 같이
그냥 부풀어 오른 모양입니다. 물론 우리는 컨텍스트 없이는 말할 수 없지만, 주석의 설명에 대해서는 ... – sehe
http://blogs.msdn.com/b/mhop/archive/2006/12/12/implicit-and- explicit-interface-implementations.aspx이 링크를 확인하십시오. 나는 그것이 당신을 도울 것이라고 생각합니다. –
클래스가 'C'에서 상속하여'f2()'를 가져와야하는 경우 인터페이스가있는 이유는 무엇입니까? 또한 인터페이스에서 선언하는 것과는 반대로,'f2()'를 확장 메소드로 구현하는 것을 고려 했습니까? –