Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote