Creating Abstract Class

-여러 클래스에 공통적으로 사용될 수 있는 추상클래스를 바로 작성하거나 기존 클래스의 공통 부분을 뽑아서 추상클래스를 만든다.

class Marine {
    int x,y;
    void move(int x, int y) {..}
    void stop() {..}
    void stimPack() {..}
}
class Tank {
    int x,y;
    void move(int x, int y) {..}
    void stop() {..}
    void changeMode() {..}
}
class Dropship {
    int x,y;
    void move(int x, int y) {..}
    void stop() {..}
    void load() {..}
    void unload() {..}
}

extract the common method by using abstract modifier(제어자) and creating "Unit" abstract class :

For someone who don't get it understand why use Abstract class

  1. Easy to maintain

  2. Easy to create class

  3. Remove duplication

by using Meaningful steps of abstract class, can use mid class.

Abstract <-> Specific

Abstract code is more easier than specified code to modify code.

추상 클래스 타입 참조 변수로 자손 객체 담을 수 있다.

once write abstract code, it is more broad.

no need to create every single calendar.

easy to modify : just modify getInstance method

Last updated

Was this helpful?