Is it some kind of bad design to have something like this: public interface IFoo
ID: 645832 • Letter: I
Question
Is it some kind of bad design to have something like this:
public interface IFooStream
{
long Length { get; }
long Position {get; set;}
//...
}
public interface IReadableFooStream<T> : IFooStream
{
int Read(T[] buffer, int offset, int count);
}
public interface IByteStream : IReadableFooStream<byte>
{
}
public interface IFloatStream : IReadableFooStream<float>
{
}
How would you solve something like this? I definitely must have the IByteStream and the IFloatStream interface.
Explanation / Answer
I definitely must have the IByteStream and the IFloatStream interface.
Without a compelling reason, I definitely say you don't. Do you make a ByteList or a FloatList? No, you leave List be and let people parameterize it.
This sort of aliasing can occasionally be useful, but more often it is a code smell that your interface/class is too abstract (or doing too many things). You're allowing things to be parameterized to the n-th degree, and that is usually not needed.
How would you solve something like this?
In my experience, an IFooStream isn't useful by itself. I would make a read stream, a write stream, and a combination maaaaybe with a base interface if/when I find I actually need it. Assuming of course that the .NET streams are somehow incapable of supplying the interface I need to do the work...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.