Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error } What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns pr…
The MargheritaPizzaBuilder is a concrete implementation of the IPizzaBuilder interface. It builds a specific type of pizza (Margherita in this case) by setting the dough, sauce, and adding toppings. The Build() method re…
The DrawingAPI1 and DrawingAPI2 are concrete implementations of the IDrawingAPI interface. These classes implement the specific drawing logic for rendering circles, but they could use different libraries or methods (e.g.…
The Adapter class implements the ITarget interface, and it wraps an instance of the Adaptee class. It delegates calls from Request() to the SpecificRequest() method of the Adaptee, making the two interfaces compatible. p…
The IButton and ICheckbox interfaces define the general contract for products. Each concrete product (e.g., WindowsButton, MacButton) will implement the Render method to display platform-specific UI elements. public inte…
Answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects…
Follow: What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) When you would and would not use it in production Real-…
nd undoing commands. When a command is executed, it’s pushed onto the stack. The Undo() method pops the last executed command and undoes its ction. public class TextEditor { private readonly Stack<ICommand> _comman…
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 Piz…
Answer: daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. } } What interviewers expect A clear definition tied to GoF Patterns in Gang of…
Answer: The Product class represents an individual product with a property Name. This is the item that we will iterate over in the collection. public class Product { public string Name { get; } public Product(string name…
The client creates a list of shopping cart elements (books, fruits), and then applies the visitor (ShoppingCart) to calculate the total cost, which includes applying the discount to books. class Program { static void Mai…
These subclasses of LoggerFactory override the CreateLogger method to return the appropriate logger type (either FileLogger or ConsoleLogger). FileLoggerFactory: public class FileLoggerFactory : LoggerFactory { public ov…
The MilkDecorator and SugarDecorator classes extend the CoffeeDecorator class and override the Cost() and Description() methods to add specific behavior (like adding the price of milk or sugar). MilkDecorator: public cla…
The TextEditor class is the invoker that invokes commands. It holds a stack of commands (_commandHistory) and is responsible for executing and undoing commands. When a command is executed, it’s pushed onto the stack. The…
The PizzaDirector class orchestrates the pizza building process. It uses a builder to construct a specific type of pizza (like Margherita) by calling the appropriate methods on the builder. It then returns the final prod…
The Circle class is a refined abstraction that extends the Shape class and provides the implementation for the Draw() method. It uses the passed IDrawingAPI to draw the circle. public class Circle : Shape { private doubl…
WindowsButton, MacButton, WindowsCheckbox, and MacCheckbox are concrete implementations of the IButton and ICheckbox interfaces. Each one provides a platform-specific rendering logic. public class WindowsButton : IButton…
lice received: Hi Alice! How It Works: What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) When you would and would…
Answer: daptee.SpecificRequest(), thus enabling compatibility between incompatible systems. Key Benefits of the Adapter Pattern: What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns p…
How It Works: Follow: What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) When you would and would not use it in pr…
dd text to the document and then undo the action. The text is added via the AddTextCommand, and after executing the command, the document’s content is displayed. Then, the Undo() method is called, and the content is reve…
nd pass it to a PizzaDirector. The director uses the builder to construct a Margherita pizza and then prints the result. class Program { static void Main() { IPizzaBuilder builder = new MargheritaPizzaBuilder(); PizzaDir…
PIs (DrawingAPI1 and DrawingAPI2). The client code can easily switch between different rendering styles without changing the shape itself. class Program { static void Main() { Shape circle1 = new Circle(5, 10, 2, new Dra…
Answer: The ProductCollection holds the actual list of products. It implements IAggregate&lt;Product&gt;, which provides an iterator to traverse through the collection. What interviewers expect A clear definition…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error }
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
IPizzaBuilder interface. It builds a specific type of pizza (Margherita in
this case) by setting the dough, sauce, and adding toppings. The Build()
method returns the fully constructed pizza.
public class MargheritaPizzaBuilder : IPizzaBuilder
{
private Pizza _pizza = new Pizza();
public void SetDough(string dough) => _pizza.Dough = dough;
public void SetSauce(string sauce) => _pizza.Sauce = sauce;
public void AddTopping(string topping) =>
_pizza.Toppings.Add(topping);
public Pizza Build() => _pizza;
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
IDrawingAPI interface. These classes implement the specific drawing logic
for rendering circles, but they could use different libraries or methods (e.g.,
OpenGL, DirectX, Canvas API).
public class DrawingAPI1 : IDrawingAPI
{
public void DrawCircle(double x, double y, double radius) =>
Console.WriteLine($"Drawing Circle at ({x}, {y}) with radius
{radius} using API 1.");
}
public class DrawingAPI2 : IDrawingAPI
{
public void DrawCircle(double x, double y, double radius) =>
Console.WriteLine($"Drawing Circle at ({x}, {y}) with radius
{radius} using API 2.");
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
instance of the Adaptee class. It delegates calls from Request() to the
SpecificRequest() method of the Adaptee, making the two interfaces
compatible.
public class Adapter : ITarget
private readonly Adaptee _adaptee;
public Adapter(Adaptee adaptee) => _adaptee = adaptee;
public void Request() => _adaptee.SpecificRequest();
Gang of Four Patterns Design Patterns in C# · GoF Patterns
products. Each concrete product (e.g., WindowsButton, MacButton) will
implement the Render method to display platform-specific UI elements.
public interface IButton { void Render(); }
public interface ICheckbox { void Render(); }Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Follow:
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
nd undoing commands. When a command is executed, it’s pushed onto the
stack. The Undo() method pops the last executed command and undoes its
ction.
public class TextEditor
{
private readonly Stack<ICommand> _commandHistory = new
Stack<ICommand>();
public void ExecuteCommand(ICommand command)
{
command.Execute();
_commandHistory.Push(command);
}
public void Undo()
{
if (_commandHistory.Count > 0)
{
var command = _commandHistory.Pop();
command.Undo();
}
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
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 _builder.Build();
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. } }
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The Product class represents an individual product with a property Name. This is the item that we will iterate over in the collection. public class Product { public string Name { get; } public Product(string name) => Name = name; }
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
the visitor (ShoppingCart) to calculate the total cost, which includes applying the
discount to books.
class Program
{
static void Main()
{
var items = new List<IShoppingCartElement>
{
new Book(20),
new Fruit(5)
};
var cart = new ShoppingCart();
foreach (var item in items)
{
item.Accept(cart); // Visitor applies operation
(discount/tax)
}
Console.WriteLine($"Total: {cart.GetTotal()}"); // Total:
24.5 (Book with discount + fruit without discount)
}
}
Output:
Total: 24.5
How the Visitor Pattern Works:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
to return the appropriate logger type (either FileLogger or
ConsoleLogger).
FileLoggerFactory:
public class FileLoggerFactory : LoggerFactory
{
public override ILogger CreateLogger() => new FileLogger();
}
ConsoleLoggerFactory:
public class ConsoleLoggerFactory : LoggerFactory
{
public override ILogger CreateLogger() => new ConsoleLogger();
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
CoffeeDecorator class and override the Cost() and Description()
methods to add specific behavior (like adding the price of milk or sugar).
MilkDecorator:
public class MilkDecorator : CoffeeDecorator
{
public MilkDecorator(ICoffee coffee) : base(coffee) { }
public override double Cost() => base.Cost() + 0.50; // Add cost
of milk
public override string Description() => base.Description() + ",
Milk"; // Add milk to description
}
SugarDecorator:
public class SugarDecorator : CoffeeDecorator
{
public SugarDecorator(ICoffee coffee) : base(coffee) { }
public override double Cost() => base.Cost() + 0.25; // Add cost
of sugar
public override string Description() => base.Description() + ",
Sugar"; // Add sugar to description
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
stack of commands (_commandHistory) and is responsible for executing
and undoing commands. When a command is executed, it’s pushed onto the
stack. The Undo() method pops the last executed command and undoes its
action.
public class TextEditor
private readonly Stack<ICommand> _commandHistory = new
Stack<ICommand>();
public void ExecuteCommand(ICommand command)
command.Execute();
_commandHistory.Push(command);
public void Undo()
if (_commandHistory.Count > 0)
var command = _commandHistory.Pop();
command.Undo();
Follow:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
builder to construct a specific type of pizza (like Margherita) by calling the
appropriate methods on the builder. It then returns the final product.
Follow:
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();
Gang of Four Patterns Design Patterns in C# · GoF Patterns
provides the implementation for the Draw() method. It uses the passed
IDrawingAPI to draw the circle.
public class Circle : Shape
{
private double _x, _y, _radius;
public Circle(double x, double y, double radius, IDrawingAPI
drawingAPI)
: base(drawingAPI)
{
_x = x;
_y = y;
_radius = radius;
}
public override void Draw() => _drawingAPI.DrawCircle(_x, _y,
_radius);
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
concrete implementations of the IButton and ICheckbox interfaces. Each
one provides a platform-specific rendering logic.
public class WindowsButton : IButton
{
public void Render() => Console.WriteLine("Rendering Windows
Button.");
}
public class MacButton : IButton
{
public void Render() => Console.WriteLine("Rendering Mac
Button.");
}
public class WindowsCheckbox : ICheckbox
{
public void Render() => Console.WriteLine("Rendering Windows
Checkbox.");
}
public class MacCheckbox : ICheckbox
{
public void Render() => Console.WriteLine("Rendering Mac
Checkbox.");
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
lice received: Hi Alice! How It Works:
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: daptee.SpecificRequest(), thus enabling compatibility between incompatible systems. Key Benefits of the Adapter Pattern:
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
How It Works: Follow:
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
dd text to the document and then undo the action.
command, the document’s content is displayed. Then, the Undo() method is
called, and the content is reverted to its previous state (empty).
class Program
{
static void Main()
{
var document = new Document();
var textEditor = new TextEditor();
var command = new AddTextCommand(document, "Hello, World!");
textEditor.ExecuteCommand(command);
Console.WriteLine(document); // Outputs: Hello, World!
textEditor.Undo();
Console.WriteLine(document); // Outputs: (empty)
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
nd pass it to a PizzaDirector. The director uses the builder to construct a
Margherita pizza and then prints the result.
class Program
{
static void Main()
{
IPizzaBuilder builder = new MargheritaPizzaBuilder();
PizzaDirector director = new PizzaDirector(builder);
Pizza pizza = director.ConstructMargheritaPizza();
Console.WriteLine(pizza);
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
PIs (DrawingAPI1 and DrawingAPI2). The client code can easily switch
between different rendering styles without changing the shape itself.
class Program
{
static void Main()
{
Shape circle1 = new Circle(5, 10, 2, new DrawingAPI1());
Shape circle2 = new Circle(5, 10, 2, new DrawingAPI2());
circle1.Draw(); // Outputs: Drawing Circle at (5, 10) with
radius 2 using API 1.
circle2.Draw(); // Outputs: Drawing Circle at (5, 10) with
radius 2 using API 2.
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The ProductCollection holds the actual list of products. It implements IAggregate<Product>, which provides an iterator to traverse through the collection.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.