CSC/ECE 517 Fall 2007/wiki3 4 rl
Assignment
Take the Interface Segregation principle and catalog the information on it available on the Web. We didn't cover it in class, but you can look it up on the Web or in the ACM DL. Find good descriptions and good, concise, understandable examples. Tell which you consider the best to present to a class.
Note to Reviewers: To create this wiki, I did extensive searching on Google, IEEE, and the ACM Digital Library. There are very few resources that address ISP beyond a sentence or two. This is why my wiki is fairly short. Also, there weren't enough resources for it to make sense to split them out into "good descriptions" vs "good examples". There was too much overlap between the two. Please note also that all prose on this page is original.
Introduction
The Interface Segregation Principle (ISP) is a design principle that calls for small, cohesive interfaces. All methods contained in an interface should apply to all clients of that interface; that is, there should be no methods in the interface that are only applicable to a subset of the interface's clients. Otherwise, there is an undesirable coupling between those clients that do require particular methods in the interface and those that do not. A good rule of thumb is that if you find yourself writing a lot of no-op methods in your implementations of the interface, you've probably violated ISP and should rethink your design.
For example, say you have an interface called Creature. It is implemented by objects of all types of living creatures, such as mammals, reptiles, etc. By the Interface Segregation Principle, a method named getHairColor does not belong in the Creature interface, since it applies to some creatures (such as mammals) but not to others (such as reptiles).
Interface Segregation Principle Resources on the Web
Following is a catalog of the best Interface Segregation Principle resources on the Web. Those containing the most useful examples are marked with a and include a description of the example. The resource that is best for teaching ISP to a class is marked with a .
http://www.objectmentor.com/resources/articles/isp.pdf
This article, "The Interface Segregation Principle," is the seminal work on ISP. The author, Robert Martin, presents the disadvantages of what he calls "fat" or "polluted" interfaces. Martin summarizes the ISP as "Clients should not be forced to depend upon interfaces that they do not use."
Martin provides a detailed example involving the user interface of an ATM machine. He shows a design that violates the ISP, and then tells the reader how to fix it. This example, written in C++, is worth reading but is also very involved and somewhat difficult to follow.
http://doodleproject.sourceforge.net/articles/2001/interfaceSegregationPrinciple.html
Like the original Martin article, this page describes fat interfaces and why they should be avoided.
The ISP example on this page concerns an online store that sells both books and CDs. The example offers a solution that violates the ISP, and then presents a proper design.
http://www.everything2.com/index.pl?node_id=1259576
This page presents ISP in the context of the "Few Interfaces" and "Small Interfaces" rules of OO design. It discusses the benefits of these two rules, and shows how they relate to ISP.
http://www.oodesign.com/oo_principles/oo_principles/interface_sergregation_principle.html
Though not particularly well written, this page is unique in that it presents the ISP in the format of a design pattern. It is organized into Motivation, Intent, Example, and Conclusion.
If you can get past the egregious spelling, grammatical, and coding errors, you'll find the example on this page simple and straightforward. The author uses the concept of a Worker who both performs work and eats lunch, then shows how a Robot worker doesn't eat and shouldn't have to implement the eat method.
http://www.ddj.com/blog/architectblog/archives/2006/06/interface_segre.html
Blogger Arnon Rotem-Gal-Oz refers to ISP as a "poor man's Single Responsibility Principle," and considers it a special case of Separation of Concerns. He also points his readers to another source that discusses how to determine what client-specific interfaces to create for any given application.
http://www.nada.kth.se/~karlm/prutt05/lectures/prutt05_lec11.ppt#31
These lecture notes contain a clear and concise description of ISP, and also present the problem and two solutions as a general formula.
http://ifacethoughts.net/2006/03/28/interface-segregation-principle/
This site provides a quick and easy description of ISP, as well as an example involving cell phones that double as MP3 players. It also recommends the Law of Demeter for help in determining interfaces.
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx
This page offers a handful of descriptions of ISP as well as a brief example involving an inventory control system.
http://javaboutique.internet.com/tutorials/JavaOO/interface_segregation.html
This article states the ISP as "Many specific interfaces are better than a single general interface." It talks about ISP in the context of the Java programming language and provides some background information on interfaces and inheritance.
The example in this article shows what goes wrong if you have file data access objects and database data access objects attempting to use the same interface. Because the behaviors of these two objects are so different, they should not share an interface.
This is the best resource for presenting the Interface Segregation Principle to a class. The description is clear and well-written and provides the right level of detail for covering the topic in an Object-Oriented Design course. The example is also the best that I have seen. It is very clear and easy to follow.
References
- The Interface Segregation Principle
- DoodleProject - Interface Segregation Principle
- Everything2 - Interface Segregation Principle
- OOD Principles - Interface Segregation Principle
- If You Build It... Will They Come? Interface Segregation Principle
- Lecture Notes - ISP Interface Segregation Principle
- Java Boutique - Fine-tuning Abstraction: Interface Segregation Principle
- ifacethoughts - Interface Segregation Principle
- David Hayden - Interface Segregation Principle