On Nov 1, 2:24 pm, Edward.Sht...@gmail.com wrote:
I must be breaking some rule of Object-Oriented Programming, but I
can't figure out how else to do it.
I have an interface, let's call it Formatter();
public interface Formatter {
public void format(Item item);
}
pretty self explanantory.
Problem is that I want Item itself to be an interface because
implementors of Formatter will want to deal with their more specific
types if Item's. So I am forced to classcast to those more specific
types of Item's in the implementing classes of Formatter, which sends
up a red flag to me.
How else can I do this?
Generics might help here:
public interface Formatter<T> {
public void format (T value);
}
However, I suspect you have a deeper design problem that this will
merely move around. Do you actually need all formatters for distinct,
non-overlapping value types to share a common interface? Why? Expand
a bit on how you're planning on using this and maybe there's a better
way :)
-O