Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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<Product>, which provides an iterator to traverse through the collection. What interviewers expect A clear definition…
The client code creates a ProductCollection and uses the iterator to sequentially access each product in the collection. It doesn’t need to know the internal structure of the collection (whether it’s a list, array, or an…
The Application class accepts an IUIFactory in its constructor. This means the client code can choose which concrete factory (Windows or Mac) to use without changing the Application class itself. public class Application…
Answer: ctual construction steps can differ based on the type of pizza (e.g., Margherita vs. Pepperoni). Key Benefits of the Builder Pattern: What interviewers expect A clear definition tied to GoF Patterns in Gang of Fo…
PIs (e.g., DrawingAPI3, DrawingAPI4) without needing to modify the existing code. Each concrete drawing API (DrawingAPI1, DrawingAPI2) provides its own implementation of the DrawCircle method, enabling the flexibility to…
pplication app = new Application(factory); pp.Render(); } } What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) Whe…
Product 1 Product 2 Product 3 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…
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.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
sequentially access each product in the collection. It doesn’t need to know the
internal structure of the collection (whether it’s a list, array, or any other data
structure).
Benefits of the Iterator Pattern:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
means the client code can choose which concrete factory (Windows or Mac)
to use without changing the Application class itself.
public class Application
{
private readonly IButton _button;
private readonly ICheckbox _checkbox;
public Application(IUIFactory factory)
{
_button = factory.CreateButton();
_checkbox = factory.CreateCheckbox();
}
public void Render()
{
_button.Render();
_checkbox.Render();
}
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: ctual construction steps can differ based on the type of pizza (e.g., Margherita vs. Pepperoni). Key Benefits of the Builder 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
PIs (e.g., DrawingAPI3, DrawingAPI4) without needing to modify the existing
code.
implementation of the DrawCircle method, enabling the flexibility to draw in
different styles or using different libraries.
Key Benefits of the Bridge Pattern:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
pplication app = new Application(factory); pp.Render(); } }
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
Product 1 Product 2 Product 3 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.