![]() ![]() Break down the fat interface to smaller and meaningful role interfaces.Martin suggested a solution that gave birth to Interface Segregation Principle. Why are you forcing your printer client to implement scanning functionality even when they don't want it? So What Did Martin Do? Problem with “fat” InterfacesĮven though the Print functionality is the only needed function for the printer-client, he/she might end up implementing some bunch of unwanted functions. But, what good does it make passing a bunch of irrelevant functions? 3. Passing a printer function to a printer client makes sense. He or she may get confused over these functions. You are passing a DLL or a library which contains a bunch of unnecessary functions which are not all required to your client. What happens when you supply this to a client who is interested only in printing job? Recompiling the entire code even when a minor change has to be made LĮven if you make a small modification, the entire code needs to be re-compiled wasting precious development time. But, wait!īefore scrolling down, try taking a minute to make a list of potential problems with the above code. class Machine : IMachineĬonsole.WriteLine( " All Items printed" + item.Count()) Ĭonsole.WriteLine( " Items stapled" + item.Count()) Ĭonsole.WriteLine( " All Items Faxed" + item.Count()) Ĭonsole.WriteLine( " All Items Scanned" + item.Count()) Ĭonsole.WriteLine( " All Items Photo copied" + item.Count()) Code implementing the IMachine interface. The code that violates ISP interface IMachine The problematic code snippet is as follows: We will see what the problem was, how Martin proposed a solution and the birth of ISP. Xerox hired a consultant to look at what was the problem. Why? Well, we will see that in a short span of time. Soon the software was developed and printer machine was working great.īut when the time progressed, maintaining the software became difficult and further development was a nightmare. Xerox hired developers to develop software for that printer machine. The printer system could do a wide variety of jobs like printing, scanning, stapling, faxing, etc. Let us say a company, Xerox had created a new all in one printer system. Historyĭon't worry :) It's going to be interesting. You will find the examples similar but elaborated for the sake of understanding. In other words, “What is the point in selling a horse saddle for one who does not own a horse?”ĭisclaimer: The following discussion is inspired from Wikipedia. The principle states that no client should be forced to depend on methods that it does not use (Wiki). It is aimed at beginners and intermediate developers. This tip explains what is Interface Segregation Principle and its uses. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |