Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
I think you have confused the use of Abstraction and Inheritance. 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

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.