W
Ward Bekker
Consider the following class structure:
public class A
{
private X _x;
public X ProperyName { get { return _x;}}
public A()
{
_x = new X();
}
}
public class ASub : A
{
private XSub _xy;
public new XSub ProperyName { get { return base.X as XSub;}}
public ASub() : base()
{
_base.X = new XSub();
}
}
public class X {}
public class XSub: X
{
public string XsubVariable = "hello world";
}
As you can see there is a base class (A) and an derived class (ASub).
They both have a property (PropertyName), only ASub uses a property
type (XSub) derived from type (X), because the XsubVariable isn't
relevant for use by class A.
Although this works, i'm not certain if this is the right way to do
this, as _base.X is set two times, once in the constructor of A, and
once in the constructor ASub.
So, is this good OOP?
Bye,
Ward
public class A
{
private X _x;
public X ProperyName { get { return _x;}}
public A()
{
_x = new X();
}
}
public class ASub : A
{
private XSub _xy;
public new XSub ProperyName { get { return base.X as XSub;}}
public ASub() : base()
{
_base.X = new XSub();
}
}
public class X {}
public class XSub: X
{
public string XsubVariable = "hello world";
}
As you can see there is a base class (A) and an derived class (ASub).
They both have a property (PropertyName), only ASub uses a property
type (XSub) derived from type (X), because the XsubVariable isn't
relevant for use by class A.
Although this works, i'm not certain if this is the right way to do
this, as _base.X is set two times, once in the constructor of A, and
once in the constructor ASub.
So, is this good OOP?
Bye,
Ward