M
Mark Sisson
Hi all.
SITUATION
================
1. I have a base class with a member variable that's an object
2. I have several classes that inherit from the base class.
3. There are several methods in the base class that modify the member
variable 4. I would like to have the inherited classes override the
member variable with a new var that's a subclass of the parent's
member variable
5. When someone instantiates the subclass and calls a methods that is
only implemented by the parent class, I like that parent method to
reference the overridden member variable.
EXAMPLE
===================================
class AAA
{
public YYY m_var = new YYY();
public void TestMethod() {
//HERE I WAS HOPING THAT localvar WOULD REFERENCE A ZZZ
CLASS
//INSTANCE HERE I WAS HOPING THAT BY USING THE this KEYWORD
THAT
//THE RUNTIME CLR WOULD RECOGNIZE THAT this IS OF TYPE ZZZ
SO THE
//m_var RETURNED WOULD BE OF TYPE ZZZ.
YYY localvar = this.m_var;
//BUT IT DOESN'T....
Type t = localvar.GetType();
Debug.Print(t.FullName);
}
}
class BBB : AAA
{
public ZZZ m_var = new ZZZ();
}
class YYY
{
}
class ZZZ : YYY
{
}
Any recommendations or new patterns that might help out?
TIA
SITUATION
================
1. I have a base class with a member variable that's an object
2. I have several classes that inherit from the base class.
3. There are several methods in the base class that modify the member
variable 4. I would like to have the inherited classes override the
member variable with a new var that's a subclass of the parent's
member variable
5. When someone instantiates the subclass and calls a methods that is
only implemented by the parent class, I like that parent method to
reference the overridden member variable.
EXAMPLE
===================================
class AAA
{
public YYY m_var = new YYY();
public void TestMethod() {
//HERE I WAS HOPING THAT localvar WOULD REFERENCE A ZZZ
CLASS
//INSTANCE HERE I WAS HOPING THAT BY USING THE this KEYWORD
THAT
//THE RUNTIME CLR WOULD RECOGNIZE THAT this IS OF TYPE ZZZ
SO THE
//m_var RETURNED WOULD BE OF TYPE ZZZ.
YYY localvar = this.m_var;
//BUT IT DOESN'T....
Type t = localvar.GetType();
Debug.Print(t.FullName);
}
}
class BBB : AAA
{
public ZZZ m_var = new ZZZ();
}
class YYY
{
}
class ZZZ : YYY
{
}
Any recommendations or new patterns that might help out?
TIA