We will dig into these relations later in this article.įor now, before jumping ahead to fix the previous violation, let me first discuss what if you violate the ISP. The ISP is particularly related to the Liskov Substitution Principle, and arguably, the ISP has the same goal as the Single Responsibility Principle. In fact, SOLID principles are so close to each other. This problem is considered a violation of the Interface Segregation Principle, and if you knew about the Liskov Substitution Principle, you might think that it is a violation of it as well, which is absolutely correct. Take a close look again at the previous example, don’t you feel that it has a problem, did you know it? what do you think of the hashPassword method in the SocialRegister class, is it relevant? That’s it, your SocialRegister class ( the client) is forced to depend on the hashPassword method it doesn’t need, that’s the problem. That means you should prefer a small, cohesive interface to large, fat ones which in turn, ensures single responsible, and highly cohesive software components. Yes, as you might think, the ISP states that any client code shouldn’t be forced to depend on any interface methods they don’t use. For the sake of simplicity, I’m going to use interfaces only in this article.īefore asking the next question, I know you have others in mind, don’t worry I’ll dig into them later.Īt least, after answering these questions I think it is clear to you what is the ISP goal. Actually, it could be a usual interface or an abstract class. In such a case, the Client is your code, not the library.ĭefinitely, NO. In another case, if you have a third-party library that provides an interface that you have to implement. Here these classes are the code that interacts with the interface ILogin. Take a look at the below example:Īs you see, here the clients are SocialLogin and PasswordLogin classes. Simply, it is the code that’s interacting with the interface, it is the calling code.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |