I know this might seem a controversial question but it really is not meant to be.
is there an optimal number of methods in an interface.
For example, I personally hate an interface with 20 methods. It is just difficult to implement. The contract seems to hard to maintain.
Similarly if the number of methods is just 1. It makes me wonder if it is really a good abstraction.
Any thoughts ?
An interface should have exactly as many methods as it needs. Examples:
java.lang.Iterable– 1 methodjava.lang.Comparable– 1 methodjava.util.Collection– 14 methodsjava.util.List– 25 methods (including those from Collection)So the answer is – don’t take the number as a criterion for your interface. Instead, put methods in interfaces where they belong logically.