Lets say I have the following interfaces
// used by generators and other read only systems
interface IRealmProvider
{
Tile GetTile(int x, int y);
}
// used by interactive realms that can be modified
interface IRealm : IRealmProvider
{
bool SetTile(int x, int y, Tile tile);
}
// used by realms that have a fixed size, whether read only or writable
interface IRealmSize
{
int TilesWide { get; }
int TilesHigh { get; }
}
The interfaces are separate as I have both infinite realms with no size and bounded realms with a fixed size. Some realms will be writable, while others will not. One class uses these realms, but requires that the realm has a fixed size.
class RealmRenderer<T> where T : IRealmProvider, IRealmSize
{
public RealmRenderer(T realm) { ... }
}
Is there any drawbacks to doing it like this?
I could see an alternative like the following
interface IBoundedRealmProvider : IRealmProvider, IRealmSize { /* intentionally empty */ }
class RealmRenderer
{
public RealmRenderer(IBoundedRealmProvider realm) { ... }
}
But this creates a stricter requirement for the various realm types to implement this specific interface just to satisfy the renderer, where using generics leaves this specific requirement out of the realm implementation. It also means I'll need yet another empty interface if I want a bounded realm that is writable.
interface IBoundedRealm : IRealm, IRealmSize { /* intentionally empty */ }
interface IRealm
, but they are notpartial
.