Click here to Skip to main content
12,821,670 members (43,266 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 23 Jul 2012

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 tell 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".


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


About the Author

Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

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    Praise Praise    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 23 Jul 2012
Article Copyright 2012 by loki2302
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid