나는 모두가 아주 가까이 보이는 따라 SO 기사파생 클래스
- C#: How do I call a static method of a base class from a static method of a derived class?
- Can I have a base class where each derived class has its own copy of a static property?
- What's the correct alternative to static method inheritance?
를 읽고 내 질문과 좋은 답변을 가지고 있지만, 내 질문에 대답하지 않는 것 이외의 방법을 비 정적으로 말할 필요가 없습니다.
예 : derivedB이 속성 1,2,10,11있을 것입니다 동안
abstract public class baseClass
{
private static List<string> attributeNames = new List(new string {"property1","property2"});
// code for property definition and access
virtual public static bool ValidAttribtue(string attributeName)
{
if (attributeNames.Contains(attributeName))
return true;
else
return false;
}
}
class derivedA : baseClass
{
private static List<string> attributeNames = new List(new string {"property3","property4"});
// code for property definition and access
public static override bool ValidAttribute(string attributeName)
{
if (attributeNames.Contains(attributeName))
{
return true;
}
else
{
return base.ValidAttribute(attributeName);
}
}
}
class derivedB : baseClass
{
private static List<string> attributeNames = new List(new string {"property10","property11"});
// code for property definition and access
public static override bool ValidAttribute(string attributeName)
{
if (attributeNames.Contains(attributeName))
{
return true;
}
else
{
return base.ValidAttribute(attributeName);
}
}
}
derivedA 속성 1,2,3,4있을 것입니다. 속성 목록이 클래스 별 값인 것처럼 보입니다. 언제든지 변경할 수 없습니다. 나는 그때 그것이 정적이라고 생각할 것이다.
정적 인 방법을 사용하지 말아야한다는 의미에서 디자인이 잘못 되었습니까?
위의 예는 정적 메서드의 상속이 필요할 것이라고 생각하게 만듭니다. 그러나이 작업을 시도하면 설계상의 결함이있는 것처럼 보입니다. 누구든지 이런 식으로 클래스를 코딩하거나 구조화하는 데있어 잘못된 점을 이해할 수 있도록 도와 줄 수 있습니까?
이 실제 코드인가? 가상 정적 멤버는 가질 수 없습니다. –
아니, 가능하다고 생각했던 작업의 예제 코드 일뿐입니다. –