SimUDuck 이야기


새로운 요구사항: 오리가 날아야 한다

“ I just need to add a fly() method in the Duck class and then all the ducks will inherit it. Now’s my time to really show my true OO genius.”

class Duck {
    quack();
    swim();
    display();
    fly(); // 새로 추가
}

문제 발생

classDiagram
direction TB

class Duck {
  +quack()
  +swim()
  +display()
  +fly()
}

class MallardDuck {
  +display()
}

class RedheadDuck {
  +display()
}

class RubberDuck {
  +quack() // overridden to Squeak
  +display()
}

Duck <|-- MallardDuck
Duck <|-- RedheadDuck
Duck <|-- RubberDuck

%% Notes (use "\\n" for line breaks)
note for Duck "fly()가 부모 클래스에"
note for RubberDuck "고무 오리라서 quack()은 '삑'(Squeak) 소리로 오버라이드"