> For the complete documentation index, see [llms.txt](https://kimtaesu.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kimtaesu.gitbook.io/workspace/undefined/14.2.-lsp-liskov-substitution-principle.md).

# 클린 코더스 강의 14.2. LSP(Liskov Substitution Principle)

![S](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2)가 ![T](https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0)의 [하위형](https://ko.wikipedia.org/w/index.php?title=%ED%95%98%EC%9C%84%ED%98%95\&action=edit\&redlink=1)이라면 \
![T](https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0)의 객체를 ![S](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2)의 객체로 치환할 수 있어야 한다는 원칙이다.

![](/files/-LpLm_ynULyQkK5J0M7U)

S, T 관계를 쉽게 설명한다면 `((S)t)` 와 같이 구체화된 하위 타입으로 downcasting 을 하면 원칙 위반이다!

## 나의 생각

SOLID 5원칙 중 `SRP, OCP` 가장 중요하다고 생각하지만\
가장 중요한 원칙은 `LSP` 원칙이라고 생각한다.\
`LSP` 가 지켜져야 `OCP` 원칙을 지킬 수 있기 때문이다.

도메인 모델을 설계할 때 LSP 의 위반이라고 판단되면 즉시 LSP 원칙을 지키기 위해 수정해야 한다. \
시간이 지나고 구체화된 Type이 많아질 수록 돌이킬 수 없을 만큼의 변경을 요구하기 때문이다.&#x20;

`SnowBall 과 같이 처음에는 작은 눈덩이였지만 큰 눈덩이가 되었을 땐 이미 늦었으며 돌이키기 위한 비용은 어마어마해진다.`

참조: \
<https://ko.wikipedia.org/wiki/%EB%A6%AC%EC%8A%A4%EC%BD%94%ED%94%84_%EC%B9%98%ED%99%98_%EC%9B%90%EC%B9%99>
