gidapma ........
..... ://quizlet.com/quiz/63q5x-tamil-story-pdf-free-download
.....
Category:Tamil history
Category:Tamil literatureQ:
Efficient class hierarchy design in C#
I have a class hierarchy in which the subclass has to inherit from the base class, with all the necessary functions and properties being overridden in the subclasses.
Since it's a WCF application, I would like to use DataContracts in the classes, that's why I would like to keep the base class empty.
Let's say I have this base class:
public abstract class MyBaseClass {
public bool MyProperty { get; set; }
}
Now let's say I have these two subclasses:
public class MySubClass1 : MyBaseClass {
public override bool MyProperty { get { return true; } }
}
public class MySubClass2 : MyBaseClass {
public override bool MyProperty { get { return false; } }
}
When I call the method:
MyBaseClass baseClass = new MySubClass1();
bool result = baseClass.MyProperty;
Result is true, and it's good, but I'm facing a memory issue because of virtual calls (the base class stores the reference to the instance).
I want to do something like that:
public class MyBaseClass {
public bool MyProperty { get; set; }
}
public class MySubClass1 : MyBaseClass {
public override bool MyProperty { get; set; }
}
public class MySubClass2 : MyBaseClass {
public override bool MyProperty { get; set; }
}
That's why I could avoid the virtual call (no memory overhead), but I would have to store two instances of MyBaseClass instead of just one.
Is there any solution for this problem?
A:
You can use Interfaces and WCF Data Contracts to achieve what you want:
Create an Interface and Derive the Class with that Interface.
public interface IMyInterface {
bool MyProperty { get be359ba680
Related links:
Comments