I have several interfaces all with only a single method and they are all very similar. I know it works, but should I or should I not group them like this:
public class InterfaceGroup {
public interface Type1 {
public void method(int a);
}
public interface Type2 {
public void method(String s);
}
public interface Type3 {
public void method();
}
}
And then reference them externally as InterfaceGroup.Type1.
Yes, it is sometimes helpful to have such a design. For example, it is the choice for Map.Entry in Java standard library.
The blemish on such a design, though, is that you define a type that doesn't play the role of a type, and it is actually never appropriate to implement it. If I found out that in a library I use such a type exists for no other reason than to reduce the number of source code files, I'd be at least slightly annoyed :-) On the other hand, when I'm writing code whose scope of visibility is just within the implementation, I use such tricks remorselessly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With