Skip to content

Interfaces and Abstract Classes

Andrew Jardine

Asked Feb 21, 2007, 7:11 AM EST2 answers
Share
LinkedInX

Hi,

I really should know why this isn't working, but for some reason I can't figure it out :). I have a class... BusinessEntityBase.cs ... and then a bunch of Business Objects that inherit from it. Let's say User.cs for example.

In a separate namespace I have created an interface called IEntityManagement. It has 4 methods (CRUD) Create, Read, Update, Delete and uses the BusinessEntityBase object for parameters and return types (where required).

I then created a class called UserManager.cs that implements the IEntityManagement interface. Rather than use the BusinessEntityBase object in my parameters and return types, I am using the specific business entity. So for example... where the interface says:

BusinessEntityBase Create();

the UserManager class has...

User Create();

Problem is that I am getting compilation errors saying that I have not defined the methods. I thought, since the user class inherits the BusinessEntityBase class that it means that to the compiler a User is a BusinessEntityBase.

Why can't I use the specific business entity when defining the implementation of the interface methods?

A.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    The interface signature must be exactly the same as the overriden methods in the implementing class.  It does not matter that one inherits the other.  The signature in this case includes the return type, the parameters, and the name of the method.
    0
  • 0
    Understood. In the end I was able to do it using generics. By redefining the BusinessEntityBase as a generic class and then using it in the interface class I am now able to implement it in the adapter classes specifying which particular Business Entity I need to conform.

    Thanks!
    A.
    0