[디자인패턴] Decorator 패턴

Decorator Pattern 출처: https://golangbyexample.com/decorator-pattern-golang/ 개요 개체를 변경하지 않고 기능을 추가할 수 있음. => 이미 테스트가 끝난 코드를 수정하면 안됨 (Open-Closed Principle에 위배됨) 두가지 피자가 존재한다고 가정해보자. vegge mania pizza peppy tofu pizza UML 다이어그램 코드 pizza.go package main type pizza interface { getPrice() int } peppyPaneer.go package main type peppyPaneer struct { } func (p *peppyPaneer) getPrice() int { return 20 } veggeMania.go package main type veggeMania struct { } func (p *veggeMania) getPrice() int { return 15 } 토핑을 추가하기 위해 위쪽에 만들어진 구조체들은 더 이상 수정하면 안됨....

April 21, 2021 · 2 min · icecat471