Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- [함수 파라미터로 플래그 사용하지 않기](#함수-파라미터로-플래그-사용하지-않기)
- [사이드 이펙트 피하기](#사이드-이펙트-피하기)
- [**Classes**](#classes)
- [**Single Responsibility Principle (SRP)**](#single-responsibility-principle-srp)
- [**단일 책임 원칙(Single Responsibility Principle (SRP))**](#단일-책임-원칙single-responsibility-principle-srp)
- [**Open/Closed Principle (OCP)**](#openclosed-principle-ocp)
- [**Liskov Substitution Principle (LSP)**](#liskov-substitution-principle-lsp)
- [**Interface Segregation Principle (ISP)**](#interface-segregation-principle-isp)
Expand Down Expand Up @@ -754,19 +754,17 @@ print(person.name_as_first_and_last) # => ["Ryan", "McDermott"]

## **Classes**

### **Single Responsibility Principle (SRP)**
### **단일 책임 원칙(Single Responsibility Principle (SRP))**

Robert C. Martin writes:
Robert C. Martin 는 다음과 같이 저술하였습니다.

> A class should have only one reason to change.
> 클래스를 변경하는 이유는 오직 하나여야 합니다.

"Reasons to change" are, in essence, the responsibilities managed by a class or
function.
'변경하는 이유' 란, 본질적으로 클래스나 함수에 의해 관리되는 책임을 말합니다.

In the following example, we create an HTML element that represents a comment
with the version of the document:
다음의 예시는 문서의 버전을 포함하여 HTML 주석을 나타내는 요소를 만듭니다.

**Bad**
**나쁜 예:**

```python
from importlib import metadata
Expand All @@ -787,16 +785,16 @@ class VersionCommentElement:
VersionCommentElement().render()
```

This class has two responsibilities:
이 클래스는 두 가지 책임을 가집니다.

- Retrieve the version number of the Python package
- Render itself as an HTML element
- 파이썬 패키지의 버전 번호를 검색
- `get_version(self)` 함수의 반환 값을 HTML 요소로써 렌더링

Any change to one or the other carries the risk of impacting the other.
둘 중 어느 하나를 변경하게 되면 다른 하나에 영향을 미칠 위험성이 있습니다.

We can rewrite the class and decouple these responsibilities:
다음과 같이 클래스를 다시 작성하여 위의 책임들을 분리할 수 있습니다.

**Good**
**좋은 예:**

```python
from importlib import metadata
Expand All @@ -821,14 +819,9 @@ class VersionCommentElement:
VersionCommentElement(get_version("pip")).render()
```

The result is that the class only needs to take care of rendering itself. It
receives the version text during instantiation and this text is generated by
calling a separate function, `get_version()`. Changing the class has no impact
on the other, and vice-versa, as long as the contract between them does not
change, i.e. the function provides a string and the class `__init__` method
accepts a string.
결과적으로 클래스는 렌더링 그 자체에만 신경쓰면 됩니다. 클래스는 인스턴트화 중에 버전 텍스트를 받고 이 텍스트는 `get_version()`라는 분리된 함수에 의해 생성됩니다. 클래스를 변경해도 다른 요소에 영향이 가지 않으며, 이는 반대의 경우에도 마찬가지입니다. 즉, 함수는 문자열을 제공하고 클래스의 `__init__` 메서드는 문자열을 수용합니다.

As an added bonus, the `get_version()` is now reusable elsewhere.
또한, `get_version()` 는 이제 어디서든 재사용할 수 있습니다.

### **Open/Closed Principle (OCP)**

Expand Down