Mid
From PDF
GoF Patterns
Gang of Four Patterns
Usage (Client Code):?
Short answer: In the Main method, we create two Number expressions (5 and 10) and then create an Add expression to combine them. Finally, we evaluate the expression by calling Interpret on the addExpression object. class Program { static void Main() {
Example code
IExpression number1 = new Number(5);
IExpression number2 = new Number(10);
IExpression addExpression = new Add(number1, number2); Console.WriteLine($"Result: {addExpression.Interpret()}"); // Outputs: Result: 15 }
}
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