Skip to content

Commit

Permalink
Merge pull request #62 from Seogeurim/Java
Browse files Browse the repository at this point in the history
[Java] μΆ”μƒν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€μ˜ 차이
  • Loading branch information
Seogeurim authored Aug 15, 2021
2 parents 15708ad + 7079176 commit cb8fccf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contents/language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

- [μžλ°” μ–Έμ–΄μ˜ ꡬ쑰와 κΈ°λ³Έ 문법](./java/1.md)
- [객체지ν–₯ 핡심 원리](./java/2.md)
- μžλ°” API ν™œμš©
- [뢀둝 - 생각해보기](./java/appendix.md)

## C++

- [C++ STL](./c++/STL.md)
- [Modern C++](./c++/moderncpp.md)
- [λ©€ν‹°μŠ€λ ˆλ“œ ν”„λ‘œκ·Έλž˜λ°](./c++/multithread-programming.md)
- [λ©€ν‹°μŠ€λ ˆλ“œ ν”„λ‘œκ·Έλž˜λ°](./c++/multithread-programming.md)
53 changes: 53 additions & 0 deletions contents/language/java/appendix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 뢀둝 - 생각해보기

> μž‘μ„±μž : [μ„œκ·Έλ¦Ό](https://github.com/Seogeurim)
<details>
<summary>Table of Contents</summary>

- [μΆ”μƒν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€μ˜ 차이](#μΆ”μƒν΄λž˜μŠ€μ™€-μΈν„°νŽ˜μ΄μŠ€μ˜-차이)

</details>

## μΆ”μƒν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€μ˜ 차이

Javaμ—λŠ” 좔상 클래슀(`abstract`)와 μΈν„°νŽ˜μ΄μŠ€(`interface`)κ°€ μžˆλ‹€. 이듀 각각은 λ¬΄μ—‡μΌκΉŒ?

#### 좔상 클래슀

상속을 ν†΅ν•΄μ„œ μžμ‹ ν΄λž˜μŠ€μ—μ„œ 좔상 λ©”μ„œλ“œλ₯Ό μ™„μ„±ν•˜λ„λ‘ μœ λ„ν•˜λŠ” ν΄λž˜μŠ€μ΄λ‹€. 좔상 λ©”μ„œλ“œλ₯Ό μ„ μ–Έν•˜κ³  μ„ μ–ΈλΆ€λ§Œ μž‘μ„±ν•˜λ©΄ ν•΄λ‹Ή 클래슀λ₯Ό 상속받은 μžμ‹ ν΄λž˜μŠ€λŠ” κ·Έ λ©”μ„œλ“œλ₯Ό λ°˜λ“œμ‹œ κ΅¬ν˜„ν•΄μ•Ό ν•œλ‹€.

```java
abstract class AbstractClass {
public abstract void AbstractMethod();
}
```

#### μΈν„°νŽ˜μ΄μŠ€

μΈν„°νŽ˜μ΄μŠ€λŠ” ν•΄λ‹Ή μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•˜λŠ” λ‹€λ₯Έ ν΄λž˜μŠ€λ“€μ—κ²Œ 도움을 μ£ΌλŠ” λͺ©μ μœΌλ‘œ μ‚¬μš©λœλ‹€. μΈν„°νŽ˜μ΄μŠ€λŠ” 좔상 ν΄λž˜μŠ€μ™€ λ‹€λ₯΄κ²Œ 닀쀑 상속(κ΅¬ν˜„)이 κ°€λŠ₯ν•˜λ‹€.

```java
interface MyInterface {
public abstract void λ©”μ„œλ“œμ΄λ¦„();
}
```

μ΄λ ‡κ²Œ 좔상 ν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€κ°€ 무엇인지 μ •μ˜ν•΄λ³΄μ•˜μ„ λ•Œ 이런 의문이 λ“€ 수 μžˆλ‹€. λͺ…μ‹œλœ λ©”μ„œλ“œλ₯Ό κ΅¬ν˜„ν•œλ‹€λŠ” μ μ—μ„œ λ‘˜μ€ μ‚¬μš© μš©λ„κ°€ λΉ„μŠ·ν•΄λ³΄μ΄λŠ”λ° μ™œ ꡳ이 좔상 ν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€λ‘œ λ‚˜λ‰˜μ–΄μžˆμ„κΉŒ? 이 λ‘˜μ„ λ‚˜λˆ μ„œ μ‚¬μš©ν•˜λŠ” κ²ƒμ—λŠ” λ°˜λ“œμ‹œ μ΄μœ κ°€ μžˆλ‹€. κ·Έ 차이점에 λŒ€ν•΄ μƒκ°ν•΄λ³΄μž.

### 좔상 ν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€μ˜ 차이점 및 μ‚¬μš© μš©λ„

#### μ‚¬μš© μ˜λ„μ˜ 차이

좔상 ν΄λž˜μŠ€λŠ” **상속**, μΈν„°νŽ˜μ΄μŠ€λŠ” **κ΅¬ν˜„**ν•΄μ„œ μ‚¬μš©ν•œλ‹€. 즉 이 λ‘˜μ€ 상속과 κ΅¬ν˜„μ΄λΌλŠ” μ μ—μ„œ κ·Έ μš©λ„κ°€ λͺ…ν™•νžˆ κ΅¬λΆ„λœλ‹€. 상속은 `is-a` 관계λ₯Ό, κ΅¬ν˜„μ€ `can-do` 관계λ₯Ό μ˜λ―Έν•œλ‹€. Javaμ—μ„œλŠ” ν•˜λ‚˜μ˜ 클래슀만 상속이 κ°€λŠ₯ν•˜κΈ° λ•Œλ¬Έμ— ν•΄λ‹Ή 클래슀의 **ꡬ뢄**을 좔상 클래슀 상속을 톡해 ν•΄κ²°ν•˜κ³ , ν•  수 μžˆλŠ” **κΈ°λŠ₯**듀을 μΈν„°νŽ˜μ΄μŠ€λ‘œ κ΅¬ν˜„ν•œλ‹€.

#### 곡톡 κΈ°λŠ₯ μ‚¬μš© μ—¬λΆ€

λͺ¨λ“  ν΄λž˜μŠ€κ°€ μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‚¬μš©ν•΄μ„œ 클래슀 κΈ°λŠ₯듀을 κ΅¬ν˜„ν•œλ‹€λ©΄ κ³΅ν†΅μ μœΌλ‘œ ν•„μš”ν•œ κΈ°λŠ₯듀도 λͺ¨λ“  ν΄λž˜μŠ€μ—μ„œ μž¬μ •μ˜ν•΄μ•Όν•  것이닀. **κ³΅ν†΅λœ κΈ°λŠ₯이 ν•„μš”ν•  λ•ŒλŠ” 좔상 클래슀λ₯Ό 이용**ν•΄ 일반 λ©”μ„œλ“œλ₯Ό μž‘μ„±ν•˜κ³ , μžμ‹ ν΄λž˜μŠ€μ—μ„œ μ‚¬μš©ν•  수 μžˆλ„λ‘ ν•˜λŠ” 것이 νŽΈν•  것이닀.

#### 각각의 μ‚¬μš© μš©λ„

좔상 ν΄λž˜μŠ€μ™€ μΈν„°νŽ˜μ΄μŠ€λŠ” μ‚¬μš© μ˜λ„μ™€ 곡톡 κΈ°λŠ₯ μ‚¬μš© μ—¬λΆ€μ—μ„œ 차이점을 가지고 μžˆλ‹€. λ‘˜μ€ 각기 λ‹€λ₯Έ 성격을 가지고 있기 λ•Œλ¬Έμ— μ–΄λ–€ μƒν™©μ—μ„œ μ–΄λ–€ 것을 μ‚¬μš©ν•΄μ•Όν•˜λŠ”μ§€ 생각해보고 μ‚¬μš©ν•˜λŠ” 것이 μ€‘μš”ν•  것이닀.

- 좔상 클래슀 : λΆ€λͺ¨ 클래슀의 κΈ°λŠ₯을 이용 λ˜λŠ” ν™•μž₯ν•˜κ³  싢을 λ•Œ μ‚¬μš©
- μΈν„°νŽ˜μ΄μŠ€ : ν•΄λ‹Ή μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν•œ 객체듀에 λŒ€ν•΄ λ™μΌν•œ λ™μž‘μ΄ μ•½μ†λ˜μ–΄μ•Ό ν•  λ•Œ

0 comments on commit cb8fccf

Please sign in to comment.