Hi everyone,
Im learning C# and OO programming and was wondering if this design is possible? (Ill explain it, then show my current code that wont compile)
I want to have two classes, one which is lightweight, and another which has more properties. The larger one should be able to polymorph into the lightweight class.
So, i have an interface that holds the lightweight data, and a class that implements that interface along with having extra properties (this is not the problem part):
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; interface IValue
{
<span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MoreValues : IValue
{
<span style="color:Blue; public <span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; } <span style="color:Green; // from IValue
<span style="color:Blue; public <span style="color:Blue; string Value2 { <span style="color:Blue; get; <span style="color:Blue; set; } <span style="color:Green; // new
}
[/code]
Ok, so now i want to make my lightweight and heavy classes:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; class MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; virtual IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass : MyParentClass
{
<span style="color:Green; // this will not work because the datatypes need to be the same
<span style="color:Blue; public <span style="color:Blue; override MoreValues Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
[/code]
As this does not work, can anybody help me with my design? Im starting to learn generics, which i think can be used here, but I am unsure how to implement it...
Can somebody help me?
Thank you all so much in advance.
View the full article
Im learning C# and OO programming and was wondering if this design is possible? (Ill explain it, then show my current code that wont compile)
I want to have two classes, one which is lightweight, and another which has more properties. The larger one should be able to polymorph into the lightweight class.
So, i have an interface that holds the lightweight data, and a class that implements that interface along with having extra properties (this is not the problem part):
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; interface IValue
{
<span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MoreValues : IValue
{
<span style="color:Blue; public <span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; } <span style="color:Green; // from IValue
<span style="color:Blue; public <span style="color:Blue; string Value2 { <span style="color:Blue; get; <span style="color:Blue; set; } <span style="color:Green; // new
}
[/code]
Ok, so now i want to make my lightweight and heavy classes:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; class MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; virtual IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass : MyParentClass
{
<span style="color:Green; // this will not work because the datatypes need to be the same
<span style="color:Blue; public <span style="color:Blue; override MoreValues Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
[/code]
As this does not work, can anybody help me with my design? Im starting to learn generics, which i think can be used here, but I am unsure how to implement it...
Can somebody help me?
Thank you all so much in advance.
View the full article