Click here to Skip to main content
11,429,154 members (53,229 online)
Click here to Skip to main content
Technical Blog

Interface segregation principle (ISP)

, 23 Jul 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
The smaller an interface is, the better it is.

SOLID principles:

The smaller an interface is, the better it is.

The idea of interfaces is to say "implement me to say others that your class can do what I define". When you see something like:

class Button implements Clickable, Focusable, HasPosition, HasText, Widget {
  ...
}

In pure English it reads as "You can click button, it can be focused or not, it has position and text". On the other hand, when you see something like this:

class PushButton implements Button {...}

It doesn't give you any idea about what the PushButton is. There are mechanisms in Java and C# to describe the type constraints when you need to pass something that is a widget+has text+focusable.

Another point here is that classes often depend on interfaces (they require objects implementing interfaces to be passed as their constructor arguments). So, when you see something like:

...
void processItems(Iterable<Integer> items) {
  ...
}
...

You can easily tell that this method doesn't really care about order of items, it doesn't care about the number of these items, and for sure it is not going to add any new items to whatever you pass there. You can easily pass an ArrayList<T> there, but still this method says: "I don't really care if you give me a Set or an ArrayList, I just need items".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

loki2302
Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided
Follow on   Twitter

Comments and Discussions

 
QuestionNot everywhere Pin
Jasper4C#31-Jul-12 5:47
memberJasper4C#31-Jul-12 5:47 
GeneralMy vote of 3 Pin
Jasper4C#31-Jul-12 5:45
memberJasper4C#31-Jul-12 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 23 Jul 2012
Article Copyright 2012 by loki2302
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid