The Interface Segregation Principle states that:
No client should be forced to depend on methods it does not use.
According to this principle, if an interface has too many methods, then we need to divide the interface into smaller interfaces with fewer methods. A simple example of this principle is shown next.
Let us assume we are using a custom interface to detect various states of a view:
public interface ClickListener { public void onItemClickListener(View v, int pos); public void onItemLongClickListener(View v, int pos); public void onItemPressListener(View v, int pos); public void onSelectedListener(View v, int pos); }
Now, while implementing this listener, we only want the onItemClickListener or the onItemLongClickListener; the others are not required but we still have to use them in the code. This violates the Interface...