인터페이스 분리 원칙은 클라이언트가 자신이 이용하지 않는 메서드에 의존하지 않아야 한다는 원칙이다.[1] 인터페이스 분리 원칙은 큰 덩어리의 인터페이스들을 구체적이고 작은 단위들로 분리시킴으로써 클라이언트들이 꼭 필요한 메서드들만 이용할 수 있게 한다. 이와 같은 작은 단위들을 역할 인터페이스라고도 부른다.
//Large Interface
Interface ICarBoatInterface
{
void drive();
void turnLeft();
void turnRight();
void steer();
void steerLeft();
void steerRight();
}
//Interface Segregation Principle
//two small interfaces (Car, Boat)
Interface ICarInterface
{
void drive();
void turnLeft();
void turnRight();
}
Interface IBoatInterface
{
void steer();
void steerLeft();
void steerRight();
}
class Avante : ICarInterface
{
public void drive()
{
//implemenetation
}
public void turnLeft()
{
//implmementation
}
public void turnRight()
{
//implementation
}
}
class CarBoat :ICarInterface , IBoatInterface
{
public void drive()
{
//implemenetation
}
public void turnLeft()
{
//implmementation
}
public void turnRight()
{
//implementation
}
public void steer()
{
//implemenetation
}
public void steerLeft()
{
//implmementation
}
public void steerRight()
{
//implementation
}
}'Dev. > 객체지향' 카테고리의 다른 글
| Dependency Inversion principle(의존성 주입 원칙) (0) | 2022.03.29 |
|---|---|
| Liskov Substitution principle(리스코프 치환 원칙) (0) | 2022.03.29 |
| Open-closed principle(개방-폐쇄 원칙) (0) | 2022.03.29 |
| Single Responsibility(단일 책임 원칙) (0) | 2022.03.29 |