I have the following scenario in a C# application using NHibernate:
public abstract class A
{
public virtual int SomeProperty { get; protected set; }
public abstract void DoSomethingWithSomeProperty(int value);
}
public class B : A
{
public override void DoSomethingWithSomeProperty(int value)
{
SomeProperty = value + 1;
}
}
public class C : A
{
public override void DoSomethingWithSomeProperty(int value)
{
SomeProperty = value + 10;
}
}
The issue arises because NHibernate complains that method "DoSomethingWithSomeProperty" is non-virtual; I suppose this is because SomeProperty is virtual itself.
I'm aware one way I could circumvent this is by disabling lazy loading for these tables. However, this is undesirable because of the way the application was designed.
I want to force whoever inherits from A to implement DoSomethingWithSomeProperty. The best way I found to work around this issue is by making both B and C implement an interface that declares DoSomethingWithSomeProperty. But that just feels really dirty.
What is the best way to deal with this?
Abstraction
andInheritance
. You can override with Inheritance, however you implement what is declared in an abstract class. You should probably do more research on OOP techniques. – Komenge Mwandila yesterday