-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
175 additions
and
2 deletions.
There are no files selected for viewing
177 changes: 175 additions & 2 deletions
177
Chapter 07 - κ°μ²΄ λΆν΄/Section 05 - ν΄λμ€/Note.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,177 @@ | ||
# ν΄λμ€ | ||
> μμ±μ: | ||
> μμ±μ: μ΅μ κ· | ||
## λͺ©μ°¨ | ||
## λͺ©μ°¨ | ||
- [ν΄λμ€](#ν΄λμ€) | ||
- [λͺ©μ°¨](#λͺ©μ°¨) | ||
- [ν΄λμ€λ μΆμ λ°μ΄ν° νμ μΈκ°?](#ν΄λμ€λ-μΆμ-λ°μ΄ν°-νμ μΈκ°) | ||
- [νμ μΆμν](#νμ -μΆμν) | ||
- [κ°μ²΄ μ§ν₯](#κ°μ²΄-μ§ν₯) | ||
- [μΆμ λ°μ΄ν° νμ μμ ν΄λμ€λ‘](#μΆμ-λ°μ΄ν°-νμ μμ-ν΄λμ€λ‘) | ||
- [ν΄λμ€: Employee](#ν΄λμ€-employee) | ||
- [λ³κ²½μ κΈ°μ€μΌλ‘ μ ννλΌ](#λ³κ²½μ-κΈ°μ€μΌλ‘-μ ννλΌ) | ||
- [μΆμ λ°μ΄ν° νμ μλ° μ¬ν check list](#μΆμ-λ°μ΄ν°-νμ -μλ°-μ¬ν-check-list) | ||
- [κ°μ²΄ μ§ν₯ μλ° μ¬ν check list](#κ°μ²΄-μ§ν₯-μλ°-μ¬ν-check-list) | ||
- [μΆμ λ°μ΄ν° νμ vs κ°μ²΄μ§ν₯](#μΆμ-λ°μ΄ν°-νμ -vs-κ°μ²΄μ§ν₯) | ||
- [νλ ₯μ΄ μ€μνλ€](#νλ ₯μ΄-μ€μνλ€) | ||
|
||
## ν΄λμ€λ μΆμ λ°μ΄ν° νμ μΈκ°? | ||
> λλΆλΆμ νλ‘κ·Έλλ° μμ μμλ ν΄λμ€λ₯Ό μΆμ λ°μ΄ν° νμ μΌλ‘ μ€λͺ νλ€. <br> | ||
> κ·Έλ¬λ λͺ νν μλ―Έμμ μΆμ λ°μ΄ν° νμ κ³Ό ν΄λμ€λ λμΌνμ§ μλ€. | ||
<center> | ||
|
||
|κ°μ²΄μ§ν₯ νλ‘κ·Έλλ° (Object-Oriented Programming)|κ°μ²΄κΈ°λ° νλ‘κ·Έλλ°(Object-Based Programming)| | ||
|:---|:---| | ||
|- μμκ³Ό λ€νμ±μ μ§μνλ νλ‘κ·Έλλ° κΈ°λ²|- μμκ³Ό λ€νμ±μ μ§μνμ§ μλ μΆμ λ°μ΄ν° νμ κΈ°λ°μ νλ‘κ·Έλλ° κΈ°λ²| | ||
|- ν΄λμ€: μ μ°¨λ₯Ό μ£Όμνν κ²|- μΆμ λ°μ΄ν° νμ : Typeμ μΆμνν κ²| | ||
|
||
</center> | ||
|
||
### νμ μΆμν | ||
|
||
<center> | ||
|
||
![image](https://github.com/luke0408/study_for_object/assets/98688494/239e5426-10ab-4823-95cd-32a7cef1a564) | ||
|
||
</center> | ||
|
||
- κ°λ³ μ€νΌλ μ΄μ μ΄ λͺ¨λ κ°λ μ μΈ νμ μ λν ꡬνμ ν¬κ΄ νλλ‘ ν¨μΌλ‘μ¨ νλμ 물리μ μΈ νμ μμ μ 체 νμμ κ°μΆλ€. | ||
- νμ μΆμνλ μ€νΌλ μ΄μ μ κΈ°μ€μΌλ‘ νμ μ ν΅ν©νλ λ°μ΄ν° μΆμν κΈ°λ²μ΄λ€. | ||
|
||
### κ°μ²΄ μ§ν₯ | ||
|
||
<center> | ||
|
||
![image](https://github.com/luke0408/study_for_object/assets/98688494/07e8a3b6-188d-40af-97f2-2a7f7737cc0e) | ||
|
||
</center> | ||
|
||
- νμ μ κΈ°μ€μΌλ‘ μ€νΌλ μ΄μ μ λ¬Άλλ€. | ||
- λ κ°μ§ μ΄μμ ν΄λμ€λ‘ λΆλ¦¬ν κ²½μ° κ³΅ν΅λ‘μ§μ μ΄λμ λ κ²μΈμ§κ° μ΄μ | ||
- κ³΅ν΅ λ‘μ§μ μ 곡νκΈ° μν κ°λ¨ν λ°©λ²μ κ³΅ν΅ λ‘μ§μ ν¬ν¨ν λΆλͺ¨ ν΄λμ€λ₯Ό μ μνκ³ μμ μν¨λ€. | ||
- ν΄λΌμ΄μΈνΈλ λΆλͺ¨ ν΄λμ€ μ°Έμ‘°μμ λν΄ λ©μΈμ§λ₯Ό μ μ‘νλ©΄ μ€μ ν΄λμ€κ° 무μμΈμ§μ λ°λΌ λ€λ₯Έ λ©μλκ° μ€νλλ€. | ||
- μ€μ λ‘ λ΄λΆμμ μνλλ μ μ°¨λ λ€λ₯΄μ§λ§ ν΄λμ€λ₯Ό μ΄μ©ν λ€νμ±μ μ μ°¨μ λν μ°¨μ΄μ μ κ°μΆλ€. | ||
- λ°λΌμ κ°μ²΄μ§ν₯μ μ μ°¨ μΆμν(procedural abstraction)μ΄λ€. | ||
|
||
## μΆμ λ°μ΄ν° νμ μμ ν΄λμ€λ‘ | ||
|
||
### ν΄λμ€: Employee | ||
|
||
- λ€μκ³Ό κ°μ Employee ν΄λμ€λ₯Ό μ μνλ€κ³ κ°μ νμ. | ||
- Employee ν΄λμ€λ μ΄λ¦κ³Ό κΈμ¬λ₯Ό κ°μ§λ€. | ||
- Employee ν΄λμ€λ μ κ· μ§μκ³Ό μλ₯΄λ°μ΄νΈ μ§μ νμ μ΄ κ³΅ν΅μ μΌλ‘ κ°μ ΈμΌ νλ μμ±κ³Ό λ©μλλ₯Ό μ μνλ€. | ||
|
||
```java | ||
public abstract class Employee { | ||
private String name; | ||
private int basePay; | ||
|
||
public Employee(String name, int basePay) { | ||
this.name = name; | ||
this.basePay = basePay; | ||
} | ||
|
||
abstract int calculatePay(int taxRate); | ||
|
||
abstract int monthlyPay(); | ||
} | ||
``` | ||
|
||
- μ κ· μ§μ | ||
|
||
```java | ||
public class SalariedEmployee extends Employee { | ||
SalariedEmployee(String name, int basePay) { | ||
super(name, basePay); | ||
} | ||
|
||
@Override | ||
int calculatePay(int taxRate) { | ||
return basePay - (basePay * taxRate); | ||
} | ||
|
||
@Override | ||
int monthlyPay() { | ||
return basePay | ||
} | ||
} | ||
``` | ||
|
||
- μλ₯΄λ°μ΄νΈ μ§μ | ||
|
||
```java | ||
public class HourlyEmployee extends Employee { | ||
private int timeCard; | ||
|
||
HourlyEmployee(String name, int basePay, int timeCard) { | ||
super(name, basePay); | ||
this.timeCard = timeCard; | ||
} | ||
|
||
@Override | ||
int calculatePay(int taxRate) { | ||
return (basePay * timeCard) - ((basePay * timeCard) * taxRate); | ||
} | ||
|
||
@Override | ||
int monthlyPay() { | ||
return 0; | ||
} | ||
} | ||
``` | ||
|
||
- μΈμ€ν΄μ€ μμ± | ||
|
||
```java | ||
Employee[] employees = { | ||
new SalariedEmployee("John", 1000), | ||
new SalariedEmployee("Mary", 1200), | ||
new SalariedEmployee("Steve", 1400), | ||
new HourlyEmployee("John", 1000, 160), | ||
new HourlyEmployee("Mary", 1200, 180), | ||
new HourlyEmployee("Steve", 1400, 200) | ||
}; | ||
``` | ||
|
||
## λ³κ²½μ κΈ°μ€μΌλ‘ μ ννλΌ | ||
> λ¨μν ν΄λμ€λ₯Ό ꡬν λ¨μλ‘ μ¬μ©νλ€λ κ²μ΄ κ°μ²΄μ§ν₯ νλ‘κ·Έλλ°μ νλ κ²μ΄ μλλ€. <br> | ||
> νμ μ κΈ°μ€μΌλ‘ μ μ°¨λ₯Ό μΆμνμ§ μμλ€λ©΄ κ·Έκ²μ κ°μ²΄μ§ν₯ λΆν΄κ° μλλ€. | ||
### μΆμ λ°μ΄ν° νμ μλ° μ¬ν check list | ||
|
||
- ν΄λμ€ λ΄λΆμ μΈμ€ν΄μ€μ νμ μ νννλ λ³μκ° μλκ°? | ||
- μΈμ€ν΄μ€ λ³μμ μ μ₯λ κ°μ κΈ°λ°μΌλ‘ λ©μλ λ΄μμ νμ μ λͺ μμ μΌλ‘ ꡬλΆνλ λ°©μμ κ°μ²΄ μ§ν₯μ μλ°νλ κ²μΌλ‘ κ°μ£Ό | ||
|
||
### κ°μ²΄ μ§ν₯ μλ° μ¬ν check list | ||
|
||
<center> | ||
|
||
![image](https://github.com/luke0408/study_for_object/assets/98688494/ea3605fe-92c8-4150-953e-766569e9f202) | ||
|
||
</center> | ||
|
||
- νμ λ³μλ₯Ό μ΄μ©ν 쑰건문μΌλ‘ ꡬλΆνλκ°? | ||
- ν΄λΌμ΄μΈνΈκ° κ°μ²΄μ νμ μ νμΈνκ³ λ©μλλ₯Ό νΈμΆνκ² ν΄μλ μλ¨ | ||
- κ°μ²΄κ° λ©μΈμ§λ₯Ό μ²λ¦¬ν μ μ ν λ©μλλ₯Ό μ²λ¦¬νκ² ν΄μΌν¨ | ||
|
||
- OCP(Open-Closed Principle) κ°λ°©-νμ μμΉμ μλ°νλκ°? | ||
- OCPλ κΈ°μ‘΄ μ½λμ μλ¬΄λ° μν₯λ λ―ΈμΉμ§ μκ³ μλ‘μ΄ κ°μ²΄ μ νκ³Ό νμλ₯Ό μΆκ°ν μ μλ κ°μ²΄μ§ν₯μ νΉμ±μ΄λ€. | ||
- κΈ°μ‘΄μ½λμμ νΉμ± λ³μμ λν λΆκΈ° λ‘μ§μ΄ μμλ€λ©΄, μλ‘μ΄ μꡬμ¬νμ΄ μλ κ²½μ° μ½λλ₯Ό μμ ν΄μΌ νλ€. | ||
- νμ§λ§ κ°μ²΄μ§ν₯μ μ΄μ©νλ©΄ μ½λ μμ μμ΄λ μλ‘μ΄ μ νκ³Ό νμλ₯Ό μΆκ°ν μ μλ€. | ||
|
||
### μΆμ λ°μ΄ν° νμ vs κ°μ²΄μ§ν₯ | ||
|
||
||μΆμ λ°μ΄ν° νμ |κ°μ²΄μ§ν₯| | ||
|:---:|:---|:---| | ||
|μ ν κΈ°μ€|μ€νΌλ μ΄μ μΆκ°κ° λΉλ²ν κ²½μ°|νμ μΆκ°κ° λΉλ²ν κ²½μ°| | ||
|νΉμ§|- μΆμλ°μ΄ν° νμ μ κ²½μ° μΌμΌμ΄ μλ‘μ΄ νμ μ λν΄ μ²΄ν¬νλ ν΄λΌμ΄μΈνΈ μ½λλ₯Ό μμ ν΄μΌ νλ€.<br>- κ°μ²΄μ§ν₯μ κ²½μ° μ½λ μμ μμ΄ μλ‘μ΄ ν΄λμ€λ₯Ό μμ κ³μΈ΅μ μΆκ°νλ©΄ λλ€.|- κ°μ²΄μ§ν₯μ κ²½μ° μλ‘μ΄ μ€νΌλ μ΄μ μ μΆκ°νκΈ° μν΄μλ μμ κ³μΈ΅μ μνλ λͺ¨λ ν΄λμ€λ₯Ό νλ²μ μμ ν΄μΌ νλ€.<br>- μΆμ λ°μ΄ν° νμ μ κ²½μ°μλ μ 체 νμ μ λν ꡬν μ½λκ° νλμ ꡬν체μ ν¬ν¨λμ΄ μλ€.<br>- λ°λΌμ μλ‘μ΄ μ€νΌλ μ΄μ μ μΆκ°νλ μμ μ΄ μλμ μΌλ‘ κ°λ¨νλ€| | ||
|
||
## νλ ₯μ΄ μ€μνλ€ | ||
> κ°μ²΄μ§ν₯μμ μ€μν κ²μ μν , μ± μ, νλ ₯μ΄λ€. | ||
- λ¨μνκ² μ€νΌλ μ΄μ κ³Ό νμ μ νμ μ μ΄λκ³ ν΄λμ€ κ³μΈ΅μ μ€νΌλ μ΄μ μ ꡬν λ°©λ²μ λΆλ°°νλ€κ³ ν΄μ κ°μ²΄μ§ν₯μ μΈ μ ν리μΌμ΄μ μ μ€κ³νλ κ²μ μλλ€. | ||
|
||
- νλ ₯μ΄λΌλ λ¬Έλ§₯μ κ³ λ €νμ§ μκ³ κ°μ²΄λ₯Ό κ³ λ¦½μν¨μ± μ€νΌλ μ΄μ μ ꡬν λ°©μμ νμ λ³λ‘ λΆλ°°νλ κ²μ μ¬λ°λ₯Έ μ κ·Όλ²μ΄ μλλ€. | ||
|
||
- νμ κ³μΈ΅κ³Ό λ€νμ±μ νγ λ ₯μ΄λΌλ λ¬Έλ§₯μμμ μ± μμ μννλ λ°©λ²μ κ΄ν΄ κ³ λ―Όν κ²°κ³Όλ¬Όμ΄μ΄μΌ νλ©° κ·Έ μμ²΄κ° λͺ©μ μ΄ λμ΄μλ μλλ€. |