Interface Segregation Principle (ISP) - SOLID Principles in c#
- Posted on
- Asp .Net
- By Deepak Talwar
says clients shouldn't have to implement interfaces they don't utilise. To avoid clients relying on extraneous methods, interfaces should be split down into smaller, more focused interfaces.
According to Interface Segregation Principle (ISP) we should break huge interfaces into smaller, more focused interfaces so clients just need to implement their desired methods.

public interface IShape
{
double Area();
double Perimeter();
}public class Circle : IShape
{
public double Radius { get; set; }public double Area()
{
return Math.PI * Radius * Radius;
}public double Perimeter()
{
return 2 * Math.PI * Radius;
}
}public class Rectangle : IShape
{
public double Width { get; set; }
public double Height { get; set; }public double Area()
{
return Width * Height;
}public double Perimeter()
{
return 2 * (Width + Height);
}
}
The Interface Segregation Principle statesthat a client shouldn't have to implement an interface it doesn't need.
Our IShape interface has Area and Perimeter functions. Circle and Rectangle implement this interface and implement these methods.
We didn't use properties Radius. Width & Height in IShape interface, as each shape has own properties