Skip to content

Commit 7e97d5f

Browse files
committed
Abstract Class vs Interface
1 parent 764410a commit 7e97d5f

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaLibrary/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaLibrary/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaLibrary/.idea/workspace.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaLibrary/JavaLibrary.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,13 @@ public class PhoneBox<T extends Phone> extends Box<T> {
11211121
}
11221122
11231123
- shape이라는 공통된 타입으로 묶어서 다룰 수 있다.
1124+
1125+
-
1126+
1127+
1128+
1129+
1130+
11241131
11251132
- 추상클래스
11261133
@@ -1149,6 +1156,30 @@ public class PhoneBox<T extends Phone> extends Box<T> {
11491156
}
11501157
```
11511158
1159+
사전적 의미로의 추상을 생각해보면, 추상은 **실체 간에 공통되는 특성을 추출**한 것을 말한다.
1160+
1161+
새, 곤충, 물고기 등 실체에서 공통되는 특성은 '동물'이다.
1162+
1163+
삼성, 현대 등 실체에서 공통되는 특성은 '회사'이다.
1164+
1165+
즉 객체를 직접 생성할 수 있는 클래스를 실체 클래스라고 하면, 이 클래스들의 공통적인 특성을 추출해서 선언한 클래스를 추상클래스라고 한다.
1166+
1167+
그래서 추상클래스가 실체클래스보다 상위/부모 클래스가 되어, 연관된 실체클래스는 추상클래스의 변수, 메소드, 빈메소드를 모두 `상속` 받을 수 있다.
1168+
1169+
1170+
1171+
추상 클래스의 용도는?
1172+
1173+
1. 실체 클래스들의 공통된 필드와 메소드의 이름을 통일할 목적
1174+
1175+
예를들면, Telephone과 Smartphone을 각기 다른 개발자가 코드를 작성한다고 했을때, 사용자의 변수명을 user, owner 이런식으로 각기 다르게 적는 경우가 생기는데, 사실 Telephone과 Smartphone은 공통적으로 사용자를 가지고 있기 때문에, Phone이라는 추상클래스를 상속받아 owner든, user든 하나를 정해서 그것을 사용하면 일관성이 확보된다.
1176+
1177+
2. 실체 클래스를 작성할 때 시간을 절약
1178+
1179+
공통된 부분을 상속받아 사용하므로 코드를 중복해서 적을 필요가 없어 시간이 절약된다.
1180+
1181+
1182+
11521183
11531184
11541185
- 익명클래스
@@ -1168,6 +1199,10 @@ public class PhoneBox<T extends Phone> extends Box<T> {
11681199
11691200
# 키워드
11701201
1202+
1203+
1204+
- Stack
1205+
11711206
```java
11721207
// HashMap<T> Character, String, Integer...
11731208
// 해시맵은 객체로 선언해주어야 한다.
@@ -1196,6 +1231,7 @@ public Solution() {
11961231
11971232
// .push(V)
11981233
1234+
// Character을 원소로 담을 스택 생성
11991235
Stack<Character> stack = new Stack<Character>();
12001236
```
12011237
@@ -1379,8 +1415,15 @@ finalize
13791415
#### 인터페이스와 추상 클래스의 차이(Interface vs Abstract Class)
13801416
13811417
```
1418+
실체클래스/클래스는
1419+
변수, 메소드만 가지고 있다. 빈메소드를 생성 시 오류발생.
13821420
1421+
인터페이스는
1422+
빈메소드를 가지고 있다.
13831423
1424+
추상클래스는
1425+
변수, 메소드, 빈메소드 모두를 가지고 있다.
1426+
객체를 직접 생성할 수 있는 클래스를 실체 클래스라고 하면, 이 클래스들의 공통적인 특성을 추출해서 선언한 클래스를 추상클래스라고 한다.
13841427
```
13851428
13861429

0 commit comments

Comments
 (0)