Skip to main content

SOLID - Interface Segregation - Principle


Introduction
Interface-segregation principle
ISP states that no client should be forced to depend on methods it does not use.ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them. Such shrunken interfaces are also called role interfaces. Having a client that is forced to use unnecessary method is regarded as violated the interface-segregation principle

Assumptions
Assuming we had completed the Liskov example in our SOLID Principle. We should now realized that the requirement stated that only messages that is sent external need to be protected. In our Liskov example, we somehow had a redundant method in InternalMessage class. This is the perfect time to make use of interface-segregation principle.

The Interface segregation
We may then introduce a separate interface for the protected message like below
Update The ExternalMessage Class
From the code snippet above, we may see that we are adding extra interface at the Extenal Message Class. We also may remove the ProtectData method at the InternalMessage class.

The Implementation
We next may perform similar implementation without any changes like below
Conclusion
From the article, we may see that we are following the SOLID principle by removing unnecessary method by using the Interface-segregation principle.

Published on : 10-Jan-2019
Ref no : DTC-WPUB-000104

About Author

My photo
Wan Mohd Adzha CAPM,MCPD,MCSD,MCSE
Passionate about new technology ( Software Engineering ) and how to build,manage and maintain them

Comments