๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš— Major Study (Bachelor)/๐ŸŸ  JAVA Programming

JAVA ํ”„๋กœ๊ทธ๋ž˜๋ฐ 8.4

by UKHYUN22 2021. 10. 29.
728x90

8.4 Interfaces and Abstract Classes

 

Coursr ํด๋ž˜์Šค๋Š” Student ํด๋ž˜์Šค๋งŒ ์ฐธ์กฐํ•œ๋‹ค.

 

 

 

Interface์™€ ํด๋ž˜์Šค์˜ ์ฐจ์ด์ 

- Constructor๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ.

- Instance variable์ด ์—†๋‹ค๋Š” ์ .

- ๋ฉ”์†Œ๋“œ์˜ body๊ฐ€ ์—†์ด ์„ ์–ธ๋งŒ ๋˜์–ด์žˆ๋‹ค๋Š” ์ 

 

 

 

 

 

 

Parent ํด๋ž˜์Šค๊ฐ€ ๋“ค์–ด๊ฐˆ ์ž๋ฆฌ์— Interface๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ๊ทธ๋Œ€๋กœ polymorphism์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค

 

 

 

Interface๊ฐ€ ํƒ€์ž…์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค.

Measurable์˜ ํƒ€์ž…์œผ๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ํ•ด๋‹น Interface์˜ ์ž๋…€ ํด๋ž˜์Šค๊ฐ€ 

๊ทธ๊ณณ์œผ๋กœ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค. Is a relation ์ด ์„ฑ๋ฆฝํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

 

์ด๋ ‡๊ฒŒ Interface๋กœ ์ƒ์„ฑํ•ด๋„ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด๋‹ค.

๋ถ€๋ชจ ํด๋ž˜์Šค์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

 

 

Inferface์—๋Š” ๋ฉ”์†Œ๋“œ์— ์„ ์–ธ๋งŒ ๋˜์–ด์žˆ์„ ๋ฟ ์ž์„ธํ•œ ๊ตฌํ˜„์ด ์•ˆ๋ผ์žˆ๊ธฐ ๋•Œ๋ฌธ์—

Measurable ํƒ€์ž…์œผ๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์›ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ

Interface ์•ˆ์— ํ•ด๋‹น ๋ฉ”์†Œ๋“œ๊ฐ€ ์„ ์–ธ๋˜์–ด ์žˆ๊ณ  Interface์˜ ์ž๋…€ ํด๋ž˜์Šค์—์„œ ๋งค์†Œ๋“œ๊ฐ€

๊ตฌํ˜„๋˜์–ด์žˆ์–ด์•ผ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

Abstract Class์™€ Interface์˜ ์ฐจ์ด์ 

Abstract ํด๋ž˜์Šค๋Š” ํด๋ž˜์Šค์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌํ˜„๋œ ๋ฉ”์†Œ๋“œ๊ฐ€ ์„ž์—ฌ ์žˆ๋‹ค.

๋‹ค์‹œ ๋งํ•ด์„œ Body๊ฐ€ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋„ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๊ตฌํ˜„ ์•ˆ๋€ ๋ฉ”์†Œ๋“œ๋„ ํ•œ ๋‘๊ฐœ ์„ž์—ฌ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๊ณ  Instance variable๋„ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค.

 

 

Interface๊ฐ€ Interface๋ฅผ Extendํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

create object, used as a base for inheritance, that would always override

 

Abstract Class๋ฅผ ๊ฐ€์ง€๊ณ  Object๋ฅผ ๋งŒ๋“ค์ง€ ๋ชปํ•œ๋‹ค.

base๋กœ ์‚ฌ์šฉ๋œ๋‹ค๋Š” ๊ฒƒ์ด parent ํด๋ž˜์Šค๋กœ๋งŒ ์‚ฌ์šฉ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.