플라이웨이트 패턴
객체를 최대한 공유해서 메모리를 절약하는 패턴
1. 플라이웨이트 구현체
// Flyweight interface
interface Font {
apply(text: string): void
}
class ConcreteFont implements Font {
constructor(public font: string, public size: number, public color: string) {}
apply(text: string) {
console.log(`Text: ${text} with Font: ${this.font},
Size: ${this.size}, Color: ${this.color}`)
}
}2. 팩토리 클래스
3. 클라이언트 코드
Last updated