Interface Segregation Principle

The interface segregation principle means that classes should not be forced to implement methods which they won’t use.

An example is that when you have a class which could extend another class for all but one method. If you extend the class and override the one method and throw an not implemented exception you violate the interface segregation principle.

A good way to solve this problem is to split the interface of the first class in 2 and make that class implement both interface. The new class only implements the 1 interface it needs.

In this manner you compose the methods of the classes in the interfaces and you will be able to utilize polymorphism in a more reliable way (A.K.A. no not implemented exceptions). Because both classes can still be switched for each other if necessary (Liskov substitution).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s