Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[백지연] 챕터 7: 자바스크립트 디자인 패턴 (1/3) #46

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

100Gyeon
Copy link
Member

No description provided.

Copy link
Contributor

@sangbooom sangbooom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻👍🏻👍🏻

Comment on lines +325 to +364
class BurgerBuilder {
public size: number;
public cheese: boolean = false;
public pepperoni: boolean = false;
public lettuce: boolean = false;
public tomato: boolean = false;

constructor(size: number) {
this.size = size;
}

addPepperoni(): BurgerBuilder {
this.pepperoni = true;
return this;
}

addLettuce(): BurgerBuilder {
this.lettuce = true;
return this;
}

addCheese(): BurgerBuilder {
this.cheese = true;
return this;
}

addTomato(): BurgerBuilder {
this.tomato = true;
return this;
}

build(): Burger {
return new Burger(this);
}
}
```

```typescript
// 다음과 같이 사용
const burger = new BurgerBuilder(14).addPepperoni().addLettuce().addTomato().build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빌더 패턴을 이해하기 좋은 예시네요 👍🏻 감사합니다

@100Gyeon 100Gyeon merged commit 51b0195 into main Oct 30, 2024
1 check passed
@100Gyeon 100Gyeon deleted the 챕터7_1/백지연 branch October 30, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants