Interface segregation principle
Line 1: | Line 1: | ||
− | Interface Segregation Principle, by [[Bob Martin | Robert Martin]] says that clients should not be forced to depend upon interfaces that they do not use. | + | Interface Segregation Principle, by [[Bob Martin | Robert Martin]] says that clients should not be forced to depend upon interfaces that they do not use. Put more simply, many client specific interfaces are better than one general purpose interface. This principle prevents [[Fat interfaces]] surfacing in the design. |
− | A good example of this principle is a modern cellphone | + | A good example of this principle is a modern cellphone which, in addition to a phone, is also a camera and an MP3 player. However some cellphones, especially older ones, do not have camera or MP3 player. Now imagine that we have an interface which provides access to the phone, camera and MP3 functionality. This would be quite a fat interface. If an older cellphone wishes to use this interface, the camera and MP3 functionality will appear to be present, but won't actually work. |
− | A better way to solve this is | + | A better way to solve this is to have small, distinct interfaces. In the case of our example we would have 3 interfaces for phone, camera and MP3 functionality. Now, modern cell phones can implement all three interfaces, while older cell phones may just implement the phone interface. This results in a cleaner design and implementation. |
== See Also == | == See Also == |
Revision as of 06:57, 29 July 2009
Interface Segregation Principle, by Robert Martin says that clients should not be forced to depend upon interfaces that they do not use. Put more simply, many client specific interfaces are better than one general purpose interface. This principle prevents Fat interfaces surfacing in the design.
A good example of this principle is a modern cellphone which, in addition to a phone, is also a camera and an MP3 player. However some cellphones, especially older ones, do not have camera or MP3 player. Now imagine that we have an interface which provides access to the phone, camera and MP3 functionality. This would be quite a fat interface. If an older cellphone wishes to use this interface, the camera and MP3 functionality will appear to be present, but won't actually work.
A better way to solve this is to have small, distinct interfaces. In the case of our example we would have 3 interfaces for phone, camera and MP3 functionality. Now, modern cell phones can implement all three interfaces, while older cell phones may just implement the phone interface. This results in a cleaner design and implementation.
See Also
References
[ISP]