PDH 개발 공부
Interface segregation, 인터페이스 분리원칙 본문
//No Interface Segregation Principle
//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
}
}
커져버린 인터페이스 ICarBoatInterface (자동차와 보트가 합쳐진) 에서 자동차 , 보트 인터페이스로 각각 나눠 클래스를 구현 해야한다.
수륙 자동차를 만들고 싶다면 자동차 , 보트를 위한 인터페이스를 상속 받는다.
'Design Pattern > SOLID' 카테고리의 다른 글
Dependency inversion , 의존관계 역전 (0) | 2021.11.09 |
---|---|
Liskov Substitution principle, 리스코프 치환 법칙 (0) | 2021.11.09 |
open Closed principles, 개방 폐쇄 원칙 (0) | 2021.11.09 |
Single Responsibility, 단일 책임 원칙 (0) | 2021.11.09 |