views:

76

answers:

4

I have got a abstract class which is implementing 3 interfaces.

 public abstract class ServiceBaseCore<Entity, EntityKey> : MarshalByRefObject, IComponentService, IEntityProvider<Entity, EntityKey>
    where Entity : IEntityId<EntityKey>, new()
    where EntityKey : IEntityKey, new()
{
 // Provided functionality/body to some methods of interface
}

Problem: i am getting error that my abstract class is not providing implementation (definition/body) to functions of interface, where as what i read is that "if a class is abstract than there is no need to provide body to all/any functions of interface its implementing".

Note: the code was generated by codeSmith even though its showing error.

please tell me where i am wrong and what i am missing.

Thanks

+1  A: 

Create abstract methods for the interface. Otherwise, the class doesn't actually necessarily implement those methods in any way, even though derived classes might (the derived versions wouldn't be available to the base via vtables and therefore could not fulfill the interface contract). That would violate the idea behind interfaces.

Note: it's late and I'm tired, so I might be wrong about the rationale. But adding abstract methods for the methods required by the interfaces will take care of the problem.

siride
+7  A: 

Just create some abstract functions, and the compiler will stop complaining:

public abstract void MyMethodDeclaredInTheInterface();

EDIT: To speed up the process, just move the caret on the interface name in your abstract class, then ctrl + . and select "Implement interface YourInterface". Then a little search and replace over the NotImplementedException should do the trick.

Johann Blais
@johann: there are around 244 such functions (showing me error) plez give me any idea so that i can make it fast
Rajesh Rolen- DotNet Developer
I have updated my answer accordingly
Johann Blais
@Rajesh Rolen: If you have 244 functions in a single type, perhaps you should consider splitting that into multiple types. See SRP http://en.wikipedia.org/wiki/Single_responsibility_principle
Brian Rasmussen
@Johann: Thanks a lot.
Rajesh Rolen- DotNet Developer
@Brian Rasmussen: No, having 244 methods is fine as long as they are correctly named. From Method1 to Method244 for example :-)
Johann Blais
A: 

You should be able to right click on the Interface name (near MyClass : IMyInterface) to see the context menu, and then choose 'Implement Interface'. Visual Studio will create all the required methods and properties to satsify the interface.

Kirk Broadhurst
A: 

You may try some IDE to save much of your time. I know exactly, that Eclipse can do this automatically.

Frozen Spider