Director (PizzaDirector): ○ The PizzaDirector class orchestrates the pizza building process. It uses a builder to construct a specific type of pizza (like Margherita) by calling the
Short answer: ppropriate methods on the builder. It then returns the final product. public class PizzaDirector { private readonly IPizzaBuilder _builder; public PizzaDirector(IPizzaBuilder builder) => _builder = builder; public Pizza ConstructMargheritaPizza() { _builder.SetDough("Thin Crust"); _builder.SetSauce("Tomato"); _builder.AddTopping("Mozzarella"); return…… ppropriate methods on the builder. It then returns the final…
Explain a bit more
product. public class PizzaDirector { private readonly IPizzaBuilder _builder; public PizzaDirector(IPizzaBuilder builder) => _builder = builder; public Pizza ConstructMargheritaPizza() { _builder.SetDough("Thin Crust"); _builder.SetSauce("Tomato"); _builder.AddTopping("Mozzarella"); return _builder.Build(); } } ppropriate methods on the builder. It then returns the final product. public class PizzaDirector { private readonly IPizzaBuilder _builder; public PizzaDirector(IPizzaBuilder builder) => _builder = builder; public Pizza ConstructMargheritaPizza()
Example code
{ _builder.SetDough("Thin Crust"); _builder.SetSauce("Tomato"); _builder.AddTopping("Mozzarella"); return _builder.Build();
}
}
Real-world example (ShopNest)
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png