![]() ![]() What we instead mean is that each lean interface caters to a consumers of a specific type of functionality or a specific set of customers all of whom have the same functional needs. What do we mean by client-specific lean interfaces– An important thing to note at this point is that when we mention client-specific lean interfaces, we do not really mean interfaces pertaining to each individual customer or user. The refactored code with multiple lean interfaces would then result into the below design – ![]() Each segregated interface is a lean interface as it only contains methods which are required for a specific client. Interface Segregation Principle avoids the design drawbacks associated with a fat interface by refactoring each fat interface into multiple segregated interfaces. A fat interface is thus an object-oriented designer’s nightmare because it makes the overall design rigid due to the enormous effort required to manage changes across all clients when making a change to a functionality/method pertaining to only one client. Even if, instead of implementing, the individual clients implement other client-specific methods with an UnsupportedOperationException, still its a colossal waste of time as well necessary exposure of methods and then their mandatory implementations. ![]() The problem with this design approach is that all clients will have to unnecessarily implement all other clients’ methods just to make their interface compile. It contains methods specific to all the clients. The GrandInterface shown above is an ideal example of a fat interface. The GrandInterface has methods pertaining to Client 1’s required functionality are shown in a block named, Client 2 specific functionality in and so on… There are multiple clients – Client 1, Client 1….Client n. Let us understand the above statement diagrammatically to make better sense of it. holding all the methods for all the clients, it is better to have multiple interfaces with each interface containing methods for a client-specific functionality or to have functionally cohesive interfaces. What the Interface Segregation Principle advocates is that instead of having a single interface catering to all the clients, i.e. Many client specific interfaces are better than one general purpose interfaceĮxamining the definition of Interface Segregation Principle – To understand Interface Segregation’s definition, let us assume that there is a system which has multiple functionalities and various clients using those functionalities via some interface such as a service or an API (Application Programming Interface). Martin has defined Interface Segregation Principle as – What is Interface Segregation Principle – Robert C. Next, an example of a fat interface is picked for a use case in Java, it is analysed and then refactored in line with the interface segregation principle to arrive at lean interfaces. It first looks at the definition of the interface segregation principle and explains its concepts. This tutorial explains the Interface Segregation Principle with example in Java. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |