[πŸ‘¨πŸ»β€πŸ’»TA9 인턴 13일차]Abstract

GoofiΒ·2023λ…„ 7μ›” 29일
0

Abstract

데이터 좔상화(Data Abstraction)

ꡳ이 λͺ°λΌλ„ λ˜λŠ” λ””ν…ŒμΌν•œ μ •λ³΄λŠ” 숨기고 κΌ­ ν•„μš”ν•œ μ •λ³΄λ§Œ κ³΅κ°œν•˜λŠ” 과정이닀.

좔상 클래슀, μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‚¬μš©ν•˜μ—¬ 데이터 좔상화가 κ°€λŠ₯ν•˜λ‹€.

Abstract

ν•΄λ‹Ή 클래슀/λ©”μ†Œλ“œκ°€ 좔상 클래슀/좔상 λ©”μ†Œλ“œμž„μ„ λͺ…μ‹œν•˜λŠ” μ˜ˆμ•½μ–΄
좔상 클래슀 : 아직 μ™„μ„±λ˜μ§€ μ•Šμ€ 클래슀
좔상 λ©”μ†Œλ“œ : μΆ”μƒν΄λž˜μŠ€ λ˜λŠ” μΈν„°νŽ˜μ΄μŠ€μ—μ„œ μ‚¬μš© κ°€λŠ₯ν•œ, 껍데기만 μžˆλŠ” λ©”μ†Œλ“œ

  • ν΄λž˜μŠ€λ‚˜ λ©”μ†Œλ“œ μ•žμ— abstractλ₯Ό λΆ™μ—¬μ„œ 좔상 클래슀 or 좔상 λ©”μ†Œλ“œμž„μ„ λͺ…μ‹œ
  • abstractλŠ” μ ‘κ·Ό μ œμ–΄μž μ•žμ΄λ‚˜ 뒀에 μ‚¬μš©ν•  수 μžˆλ‹€.
  • ν΄λž˜μŠ€μ— 좔상 λ©”μ†Œλ“œκ°€ ν¬ν•¨λ˜μ–΄ μžˆλŠ” 경우 λ°˜λ“œμ‹œ ν΄λž˜μŠ€μ— abstractλ₯Ό μž‘μ„±ν•΄μ•Όν•œλ‹€.
  • 좔상 ν΄λž˜μŠ€λŠ” 좔상 λ©”μ†Œλ“œλ₯Ό κ°€μ§ˆ μˆ˜λ„ 있고 가지지 μ•Šμ„ μˆ˜λ„ μžˆλ‹€.
  • 좔상 ν΄λž˜μŠ€λŠ” 객체λ₯Ό 생성할 수 μ—†λ‹€.
  • 좔상 ν΄λž˜μŠ€λŠ” μƒμ†ν•œ μžμ‹ ν΄λž˜μŠ€λ‘œλŠ” 객체λ₯Ό λ§Œλ“œλŠ” 것이 κ°€λŠ₯ν•˜λ‹€.
  • 좔상 λ©”μ†Œλ“œκ°€ μΆ”μƒν΄λž˜μŠ€κ°€ μžˆλ‹€κ³  ν•œλ‹€λ©΄ μžμ‹ ν΄λž˜μŠ€μ—μ„œλŠ” 좔상 λ©”μ†Œλ“œλ₯Ό λ°˜λ“œμ‹œ κ΅¬ν˜„ν•΄μ•Όλœλ‹€.

μž‘μ„±λ²•

// abstractλ₯Ό μ ‘κ·Ό μ œμ–΄μž μ•žμ— μž‘μ„±
abstract μ ‘κ·Ό μ œμ–΄μž class 클래슀λͺ… {
	abstract μ ‘κ·Ό μ œμ–΄μž λ°˜ν™˜ν˜• λ©”μ†Œλ“œλͺ…();
}

// abstractλ₯Ό μ ‘κ·Ό μ œμ–΄μž 뒀에 μž‘μ„±
μ ‘κ·Ό μ œμ–΄μž abstract class 클래슀λͺ… {
	μ ‘κ·Ό μ œμ–΄μž abstract λ°˜ν™˜ν˜• λ©”μ†Œλ“œλͺ…();
}

μ°Έκ³  λΈ”λ‘œκ·Έ

ex) μ˜ˆμ‹œ 폴더ꡬ쑰

CameraλŠ” μΆ”μƒν΄λž˜μŠ€μ΄κ³  FactoryCam, SpeedCam은 Camera μΆ”μƒν΄λž˜μŠ€λ₯Ό 상속 λ°›λŠ”λ‹€.

// Camera.java

package chap_08.camera;

public abstract class Camera {
    public void takePicture(){
        System.out.println("사진을 μ΄¬μ˜ν•©λ‹ˆλ‹€.");
    }

    public void recordVideo(){
        System.out.println("λ™μ˜μƒμ„ λ…Ήν™”ν•©λ‹ˆλ‹€.");
    }

    //좔상 λ©”μ†Œλ“œ μ„ μ–Έ 즉, κ΅¬ν˜„ν•΄μ•Ό ν•˜λŠ” λ©”μ†Œλ“œ
    public abstract void showMainFeature();
}
//FactoryCam.java

package chap_08.camera;

public class FactoryCam extends Camera {
    @Override
    public void showMainFeature() {
        System.out.println("ν™”μž¬ 감지");
    }
}
//SpeedCam.java

package chap_08.camera;

public class SpeedCam extends Camera{

    @Override
    public void showMainFeature() {
        System.out.println("속도 μΈ‘μ •, 번호 인식");
    }
}
package chap_08;

import chap_08.camera.Camera;
import chap_08.camera.FactoryCam;
import chap_08.camera.SpeedCam;

public class _01_AbstractClass {
    public static void main(String[] args) {
//        Camera camera = new Camera(); μΉ΄λ©”λΌλŠ” 객체둜 λ§Œλ“€ 수 μ—†λ‹€. μΆ”μƒν΄λž˜μŠ€μ΄κΈ° λ•Œλ¬Έμ—

//        FactoryCam factoryCam = new FactoryCam();
        Camera factoryCam = new FactoryCam(); //좔상 클래슀둜λͺ…μœΌλ‘œλ„ 객체 생성 κ°€λŠ₯
        factoryCam.showMainFeature();

//        SpeedCam speedCam = new SpeedCam();
        Camera speedCam = new SpeedCam();
        speedCam.showMainFeature();

    }
}
profile
μ˜€λŠ˜λ³΄λ‹¨ 내일이 κ°•ν•œ κ°œλ°œμžμž…λ‹ˆλ‹€!!πŸ§‘πŸ»β€πŸ’»

0개의 λŒ“κΈ€

κ΄€λ ¨ μ±„μš© 정보