If you change the return type - you're changing the contract
- you can't model that with IMinimalState
.
I'd just simplify a bit e.g.
public interface IMinimalState
{
IMinimalState generate();
int getData();
}
public interface IState : IMinimalState
{
// IState generate();
int getAnotherData();
}
public class MinimalState : IMinimalState
{
public IMinimalState generate() { return this; }
public int getData() { return 0; }
}
public class State : IState
{
IMinimalState IMinimalState.generate() { return this.generate(); }
// IState IState.generate() { return this; }
public IState generate() { return this; }
public int getData() { return 1; }
public int getAnotherData() { return 2; }
}
Note: your 'use-case' is essential here (and missing) - and drives your design. You should always supply that prior to making design decision, probably the first thing to do.
Normally if you're storing and iterating over the base interface IMinimalState
- that's all you need.
If you're accessing the object knowing
that it's State
you can use its public method for that to get the strong-type.
If you'd still want - you can have both (just uncomment the two lines).
And the last option - often used in more complex cases - is to use a Visitor
to differentiate in between IMinimalState and IState - when you have just a list of base interfaces. E.g. that's used by expressions where you need to redefine
types of parameters, sub-expressions etc. If you're interested I can post that later.