Overview of Interface Segregation Principle It states avoid tying a client class to a big interface if only a subset of this interface is really needed. Many times you see an interface which has lots of methods. This is a bad design choice since probably a class implementing. . This can make it harder to understand the purpose of a component, but it can also cause increase coupling, where by components that make use of such a component are exposed to more of that components capabilities that are appropriate.
The Interface Segregation Principle (or ISP) aims to tackle this problem by breaking a components interface into functionally separate sub-interfaces. Although a component may still end up with the same set of public members, those members will be separated into separate interfaces such that a calling component can operate on the component by referring only to the interface that concerns the calling component. Intenet Clients should not be forced to depend upon interfaces that they don't use. Example Below are the example which violates the rules of Interface segregation Principle. Suppose Our modules is having two different modules Customers and Product. Then in below example IDbService is a Generic Interface which you can pass any type of class like. Customer, Product etc as T and Tkey defines your Identification Key. It might be long, int or double as per the requirement.But if we declare it within one Interface then GetCustomersByDeptID() method is not useful for Product class. So here we rae violates the rules of Interface Segregation Principle.
public interface IDbService<T, TKey> where T : IEntity { IList<T> GetAll(); T GetById(TKey key); bool Update(T entity, TKey key); int Add(T entity); IList<Customer> GetCustomersByDeptID(int departmentId); }
public interface IDbService<T, TKey> where T : IEntity { IList<T> GetAll(); T GetById(TKey key); bool Update(T entity, TKey key); int Add(T entity); } public interface ICustomerService : IDbService<Customer, int> { IList<Customer> GetCustomersByDeptID(int departmentId); }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: