No it really doesn't. It makes sense to use inheritance properly:
public interface IVersion
{
string GetVersion();
}
public class Version : IVersion
{
string version;
public Version(string version)
{
this.version = version;
}
public string GetVersion() =>
version;
}
public class AppleVersion : IVersion
{
string version;
public AppleVersion(string version)
{
this.version = version;
}
public string GetVersion() =>
"apple-" + version;
}
public abstract class Entity
{
public IVersion Version { get; private set; }
public Entity(IVersion version) =>
Version = version;
}
public abstract class Apple : Entity
{
public readonly AppleVersion AppleVersion;
public Apple(AppleVersion version) : base(version)
{
AppleVersion = version;
}
}
That allows for "When we're working with an IApple instance we want to be able to have access to the version as IAppleVersion", as well as general access to the IVersion from an Entity.If you don't like the storage overhead, you could just downcast knowing that the Version is an AppleVersion:
public abstract class Apple : Entity
{
public AppleVersion AppleVersion => Version as AppleVersion;
public Apple(AppleVersion version) : base(version)
{
}
}
> I'm not sure that's clear but I hope you can see the problem that I'm trying to solve. I think it's the disconnect with wanting to be able to access both more specific and more general interfaces (and their properties) that causes trouble.You're describing issues with inheritance, not generics.
> I stand by my opinion though that you should be careful and in some situations be able to provide non-generic interfaces rather than requiring each method and class in a library to be generic, but that's only my opinion man :)
That's fine, you're entitled to your opinion, and if it works for you that's great. But your original comment was very 'matter of fact'. I've not seen anything that has communicated to me an issue with generics; and every example so far should have been implemented differently to the way you state (in my opinion).