CSC/ECE 517 Fall 2007/wiki3 4 sa: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:


= Introduction =
= Introduction =
All the basic design principles converge on the use of abstraction for incorporating flexibility using loose coupling behaviour. Interface Segregation Principle (ISP) is a guideline for designing different interfaces.The Interface-Segregation Principle focuses on the cohesiveness of interfaces with respect to the clients that use them.
All the basic design principles converge on the use of abstraction for incorporating flexibility using loose coupling behavior. The Interface Segregation Principle (ISP) provides guidelines for designing interfaces to classes that must provide different services to different clients. The Interface Segregation Principle focuses on the cohesiveness of interfaces with respect to the clients that use them.


= Definition =
= Definition =
ISP was originally presented in a paper by Robert C. Martin in his ''Engineering Notebook'' column for the ''C++ Report''. The paper is still available at the Object Mentor website [http://www.objectmentor.com/resources/articles/isp.pdf (ISP)].


The essence of Integration Segregation Principle is that  
The essence of Integration Segregation Principle is that  
<b>"Clients should not be forced to depend upon interfaces that they don’t use."</b>
<b>"Clients should not be forced to depend upon interfaces that they don’t use."</b>


Some other definitions of ISP are<br>
Some other definitions of ISP are:
"Many client specific interfaces are better than one general purpose interface"<br>
:"Many client specific interfaces are better than one general purpose interface"
"The dependency of one class to another one should depend on the smallest possible interface"<br>
:"The dependency of one class to another one should depend on the smallest possible interface"
"Make fine grained interfaces that are client specific."<br>
:"Make fine grained interfaces that are client specific."
 


=Examples=
=Examples=
Line 19: Line 20:
Interfaces are useful in designing real world systems, where every object can have multiple aspects. This aspect can be a facet, a behaviour, a role - any entity that qualifies the object with that aspect. Lets take a real world example - a modern cell phone (mobile) acts more than just a phone, it is a phone, a MP3 player and a video player. When I am using it as a MP3 player, I will like to specify the song I want to play and listen to it, nothing more nothing else. When I am using it as a mobile phone, I will like to provide the number and speak, nothing more nothing else. I will get extremely irritated if I am asked for a phone number when I want to listen to a song. It is better if only the relevant questions are asked.
Interfaces are useful in designing real world systems, where every object can have multiple aspects. This aspect can be a facet, a behaviour, a role - any entity that qualifies the object with that aspect. Lets take a real world example - a modern cell phone (mobile) acts more than just a phone, it is a phone, a MP3 player and a video player. When I am using it as a MP3 player, I will like to specify the song I want to play and listen to it, nothing more nothing else. When I am using it as a mobile phone, I will like to provide the number and speak, nothing more nothing else. I will get extremely irritated if I am asked for a phone number when I want to listen to a song. It is better if only the relevant questions are asked.
The cell phone had interfaces of a phone and a MP3 player. ISP advises to keep these two interfaces completely independent of each other. This way the phone can be treated purely as a phone or as a MP3 player. Programmatically, I can use only the interface of a MP3 player in my method called playSong. In future even if the interface for the phone is modified, playSong would remain the same.
The cell phone had interfaces of a phone and a MP3 player. ISP advises to keep these two interfaces completely independent of each other. This way the phone can be treated purely as a phone or as a MP3 player. Programmatically, I can use only the interface of a MP3 player in my method called playSong. In future even if the interface for the phone is modified, playSong would remain the same.
=Conclusion=
= Resources =
 
ISP is very well explained in the original paper [http://www.objectmentor.com/resources/articles/isp.pdf (ISP)], which has two examples in C++ and an early version of UML. These examples use C++'s multiple inheritance due to the lack of real interfaces in the language. Each interface is defined using an abstract class with pure virtual methods. Even when these examples are good the use of C++ and the old version of UML might make it harder for people used to languages with support for real interfaces like Java or C# to understand them.


Interface Segregation Principle's idea is to see that if there are two non-cohesive functionalities, keep them separate, so that they can be used independent of other. This avoids design of fat interfaces, and provides a clear design to the user (client). Break the functionalities into atomic interfaces that can be then individually accessed by the user.
The ISP page at Doodle Project has an example in modern UML [http://doodleproject.sourceforge.net/articles/2001/interfaceSegregationPrinciple.html].


= Resources =
A Java Boutique page is available with a very concise and clear example in UML [http://javaboutique.internet.com/tutorials/JavaOO/interface_segregation.html].


1) http://www.objectmentor.com/resources/articles/isp.pdf<br>
=Conclusion=
2) http://ifacethoughts.net/2006/03/28/interface-segregation-principle/<br>


= Further reading =
Interface Segregation Principle's idea is to see that if there are two non-cohesive functionalities, keep them separate, so that they can be used independent of other. This avoids design of fat interfaces, and provides a clear design to the user (client). Break the functionalities into atomic interfaces that can be then individually accessed by the user.


''Note: Santosh Gurijala (skgurija) and Agustin Vega-Frias (jvegafr) are the authors of this page.''
''Note: Santosh Gurijala (skgurija) and Agustin Vega-Frias (jvegafr) are the authors of this page.''

Revision as of 16:01, 18 November 2007

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.

Introduction

All the basic design principles converge on the use of abstraction for incorporating flexibility using loose coupling behavior. The Interface Segregation Principle (ISP) provides guidelines for designing interfaces to classes that must provide different services to different clients. The Interface Segregation Principle focuses on the cohesiveness of interfaces with respect to the clients that use them.

Definition

ISP was originally presented in a paper by Robert C. Martin in his Engineering Notebook column for the C++ Report. The paper is still available at the Object Mentor website (ISP).

The essence of Integration Segregation Principle is that "Clients should not be forced to depend upon interfaces that they don’t use."

Some other definitions of ISP are:

"Many client specific interfaces are better than one general purpose interface"
"The dependency of one class to another one should depend on the smallest possible interface"
"Make fine grained interfaces that are client specific."

Examples

Interfaces are useful in designing real world systems, where every object can have multiple aspects. This aspect can be a facet, a behaviour, a role - any entity that qualifies the object with that aspect. Lets take a real world example - a modern cell phone (mobile) acts more than just a phone, it is a phone, a MP3 player and a video player. When I am using it as a MP3 player, I will like to specify the song I want to play and listen to it, nothing more nothing else. When I am using it as a mobile phone, I will like to provide the number and speak, nothing more nothing else. I will get extremely irritated if I am asked for a phone number when I want to listen to a song. It is better if only the relevant questions are asked. The cell phone had interfaces of a phone and a MP3 player. ISP advises to keep these two interfaces completely independent of each other. This way the phone can be treated purely as a phone or as a MP3 player. Programmatically, I can use only the interface of a MP3 player in my method called playSong. In future even if the interface for the phone is modified, playSong would remain the same.

Resources

ISP is very well explained in the original paper (ISP), which has two examples in C++ and an early version of UML. These examples use C++'s multiple inheritance due to the lack of real interfaces in the language. Each interface is defined using an abstract class with pure virtual methods. Even when these examples are good the use of C++ and the old version of UML might make it harder for people used to languages with support for real interfaces like Java or C# to understand them.

The ISP page at Doodle Project has an example in modern UML [1].

A Java Boutique page is available with a very concise and clear example in UML [2].


Conclusion

Interface Segregation Principle's idea is to see that if there are two non-cohesive functionalities, keep them separate, so that they can be used independent of other. This avoids design of fat interfaces, and provides a clear design to the user (client). Break the functionalities into atomic interfaces that can be then individually accessed by the user.

Note: Santosh Gurijala (skgurija) and Agustin Vega-Frias (jvegafr) are the authors of this page.