- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Interface segregation principle and how to implement it in C#?
Clients should not be forced to depend upon interfaces that they don't use.
The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.
Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one submodule
Before Interface Segregation
Example
public interface IProduct { int ID { get; set; } double Weight { get; set; } int Stock { get; set; } int Inseam { get; set; } int WaistSize { get; set; } } public class Jeans : IProduct { public int ID { get; set; } public double Weight { get; set; } public int Stock { get; set; } public int Inseam { get; set; } public int WaistSize { get; set; } } public class BaseballCap : IProduct { public int ID { get; set; } public double Weight { get; set; } public int Stock { get; set; } public int Inseam { get; set; } public int WaistSize { get; set; } public int HatSize { get; set; } }
After Interface Segregation
Example
public interface IProduct { int ID { get; set; } double Weight { get; set; } int Stock { get; set; } } public interface IPants { int Inseam { get; set; } int WaistSize { get; set; } } public interface IHat { int HatSize { get; set; } } public class Jeans : IProduct, IPants { public int ID { get; set; } public double Weight { get; set; } public int Stock { get; set; } public int Inseam { get; set; } public int WaistSize { get; set; } } public class BaseballCap : IProduct, IHat { public int ID { get; set; } public double Weight { get; set; } public int Stock { get; set; } public int HatSize { get; set; } }
- Related Articles
- What is Liskov Substitution principle and how to implement in C#?
- What is dependency inversion principle and how to implement in C#?
- What is proxy design pattern and how to implement it in C#?
- How to implement Single Responsibility Principle using C#?
- How to implement Open Closed principle using C#?
- How to implement interface in anonymous class in C#?
- What is Proactive Customer Service and How to Implement It?
- What is Facade and how to implement in C#?
- How to implement dependency injection using Interface-based injection in C#?
- What is Killer Bees Financial Strategy and How to implement it?
- How to implement Flow.Publisher interface in Java 9?
- How to implement the IntPredicate interface using lambda and method reference in Java?
- How to implement ObjLongConsumer interface using lambda expression in Java?
- How to implement Function interface with lambda expression in Java?
- Why an interface cannot implement another interface in Java?

Advertisements