I have three classes that will each return a slightly different result.
// interfact to a king
public interface IKing{
public Result Get();
}
// main abstract class
public abstract class King:IKing{
public abstract Result Get();
}
// main abstract result
public abstract class Result{
public int Type {get;set;}
}
// KingA result
public class ResultA:Result{
...
}
// KingB result
public class ResultB:Result{
...
}
// concrete implementations
public class KingA:King{
public override ResultA Get(){
return new ResultA;
}
}
public class KingB:King{
public override ResultB Get(){
return new ResultB
}
}
This will not work since the King
overriden method of Get
is expecting the Result
class and will not accept its children ResultA
and ResultB
.
Is there a better approach I can take?