상태 패턴
객체의 내부 상태에 따라 행위가 달라질 때, 상태를 객체로 분리하여 조건문 없이 동작을 변경하는 패턴
1. Context 객체
class VideoPlayer {
constructor(private state: VideoPlayerState)
setState(state: VideoPlayerState) {
this.state = state
}
play() {
this.state.play()
}
stop() {
this.state.stop()
}
}2. State 인터페이스
3. State 객체
Last updated