मैं पालन अतः लेखव्युत्पन्न वर्ग का अपना स्थिर विधि में आधार वर्ग के स्थिर विधि कॉलिंग
- 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?
के माध्यम से पढ़ा है सभी बहुत के करीब लग रहे हैं मेरे प्रश्न और अच्छे जवाब हैं, लेकिन वे मेरे प्रश्न का उत्तर देने के अलावा अन्य प्रश्नों का उत्तर नहीं देते हैं कि मुझे विधि को गैर स्थैतिक बनाने की आवश्यकता है।
एक उदाहरण:
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 है, जबकि derivedB गुण 1,2,10,11 होता होगा। गुणों की सूची एक वर्ग विशिष्ट मान प्रतीत होती है और इसे किसी भी समय बदला नहीं जा सकता है। मुझे लगता है कि यह स्थिर होगा।
मेरी डिजाइन भावना है कि मैं स्थिर तरीकों का उपयोग करने के लिए जब वे नहीं होना चाहिए कोशिश कर रहा हूँ में गलत है?
ऊपर के उदाहरण मुझे लगता है कि स्थिर तरीकों में से है कि विरासत की जरूरत होगी बनाता है, फिर भी ऐसा लगता है कि एक डिजाइन दोष है यह करने के लिए कोशिश कर रहा। क्या कोई मुझे यह समझने में मदद कर सकता है कि कोडिंग या कक्षाओं को इस तरह से संरचित करने में क्या गलत है?
इस वास्तविक कोड है? आपके पास वर्चुअल स्थिर सदस्य नहीं हो सकते हैं। –
नहीं, यह एक ऑपरेशन का सिर्फ उदाहरण कोड है जिसे मैं सोच रहा था, संभव होना चाहिए। –