I am defining a geenral API which will have a number of more specific derivations and want to know if C# interfaces are powerful enough to model this, and if so how, and if not how else I might model this.
To illustrate what I am trying to do imagine an authentication API with a general interface with an Authenticate function which takes an abstract AuthenticationToken. I want to then create more specific forms of this interface with as shown ..
abstract class AuthenticationToken
{
}
interface IAthentication
{
bool Authenticate(string name, AuthenticationToken token);
}
class DoorKey : AuthenticationToken
{
}
interface IDoorAthentication : IAthentication
{
bool Authenticate(string name, DoorKey token);
}
class DoorUnlocker : IDoorAthentication
{
public bool Authenticate(string name, DoorKey token)
{
}
}
My intention is that the derived interface is constrained to comply with the high level form but that is not how C# interprets this.
Best Regards
Help me John Skeets .. you’re my only hope.
(Sorry .. my Star Wars BluRays have arrived!)
This is what you want:
Generics with constraints!