Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: This is an abstract class that declares the CreateLogger method, which is intended to return an ILogger instance. The actual instantiation is delegated to subclasses. public abstract class LoggerFactory Exa…
Short answer: The CoffeeDecorator class is an abstract class that implements the ICoffee interface and holds a reference to an ICoffee object. This class allows us to add additional behavior to the coffee object, but we…
Short answer: The Directory class represents the composite component in the tree structure. It can contain files or other directories. The Add() method is used to add components (both files and directories) to the direct…
Short answer: The Document class represents the receiver of the command. It contains the actual operations for adding and removing text from the document. The AddText and RemoveText methods manipulate the internal conten…
Short answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error } Say this in the interview Define — one clear sentence (the short answer above). Exampl…
Short answer: 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 Bui…
Short answer: 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…
Short answer: 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 element…
Short answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions. Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it removes duplication…
Short answer: How It Works:? is a common interview topic in Gang of Four Patterns. Give a clear definition, then one concrete example. Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it removes dupl…
Short answer: 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 ction. public class TextEditor { private readonly Stack<IComm…
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 = build…
Short answer: daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. Explain a bit more } } daptee adaptee = new Adaptee(); ITarget adapter = n…
Short 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 Example code { public string Name { get; } public…
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…
Short answer: These subclasses of LoggerFactory override the CreateLogger method to return the appropriate logger type (either FileLogger or ConsoleLogger). FileLoggerFactory: public class FileLoggerFactory : LoggerFacto…
Short answer: 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). MilkDecorat…
Short answer: 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…
Short answer: 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…
Short answer: 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 E…
Short answer: WindowsButton, MacButton, WindowsCheckbox, and MacCheckbox are concrete implementations of the IButton and ICheckbox interfaces. Each one provides a platform-specific rendering logic. public class WindowsBu…
Short answer: lice received: Hi Alice! How It Works: 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. Sa…
Short answer: daptee.SpecificRequest(), thus enabling compatibility between incompatible systems. Key Benefits of the Adapter Pattern: Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it removes dupl…
Short answer: How It Works: Follow: 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 int…
Short answer: And 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 MargheritaPizzaBuil…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: This is an abstract class that declares the CreateLogger method, which is intended to return an ILogger instance. The actual instantiation is delegated to subclasses. public abstract class LoggerFactory
{
public abstract ILogger CreateLogger();
}
ShopNest’s NotificationFactory creates Email or SMS senders based on user preference.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The CoffeeDecorator class is an abstract class that implements the ICoffee interface and holds a reference to an ICoffee object. This class allows us to add additional behavior to the coffee object, but we don't modify the base class (SimpleCoffee). public abstract class CoffeeDecorator : ICoffee
{ protected ICoffee _coffee; protected CoffeeDecorator(ICoffee coffee) => _coffee = coffee;
public virtual double Cost() => _coffee.Cost();
public virtual string Description() => _coffee.Description();
}
Logging and caching decorators wrap IProductRepository so core SQL code stays clean.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The Directory class represents the composite component in the tree structure. It can contain files or other directories. The Add() method is used to add components (both files and directories) to the directory. The ShowInfo() method iterates through its children and displays their information. public class Directory : IFileSystemComponent
{
private string _name;
private List<IFileSystemComponent> _children = new
List<IFileSystemComponent>();
public Directory(string name) => _name = name;
public void Add(IFileSystemComponent component) => _children.Add(component); public void ShowInfo()
{ Console.WriteLine($"Directory: {_name}"); foreach (var child in _children)
{ child.ShowInfo(); }
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The Document class represents the receiver of the command. It contains the actual operations for adding and removing text from the document. The AddText and RemoveText methods manipulate the internal content (a StringBuilder).
public class Document
{
private readonly StringBuilder _content = new StringBuilder();
public void AddText(string text) => _content.Append(text);
public void RemoveText(string text) => _content.Remove(_content.Length - text.Length, text.Length); public override string ToString() => _content.ToString();
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error }
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 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;
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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., 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
Short answer: 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 interface IButton { void Render(); }
public interface ICheckbox { void Render(); }
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: How It Works:? is a common interview topic in Gang of Four Patterns. Give a clear definition, then one concrete example.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 ction. public class TextEditor { private readonly Stack<ICommand> _commandHistory = new Stack<ICommand>(); public void ExecuteCommand(ICommand command) { command.Execute(); _commandHistory.Push(command); } public… void… 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(); } } } 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 ction. public class TextEditor { private readonly Stack<ICommand> _commandHistory = new… { command.Execute(); _commandHistory.Push(command); }
public void Undo()
{
if (_commandHistory.Count > 0)
{
var command = _commandHistory.Pop(); command.Undo(); }
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
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…
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()
{ _builder.SetDough("Thin Crust"); _builder.SetSauce("Tomato"); _builder.AddTopping("Mozzarella"); return _builder.Build();
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee.
} } daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. } } daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. } } daptee adaptee = new Adaptee(); ITarget adapter = new Adapter(adaptee); dapter.Request(); // Outputs: Specific request from daptee. } }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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;
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
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() {
IExpression number1 = new Number(5);
IExpression number2 = new Number(10);
IExpression addExpression = new Add(number1, number2); Console.WriteLine($"Result: {addExpression.Interpret()}"); // Outputs: Result: 15 }
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: These subclasses of LoggerFactory override the CreateLogger method 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();
}
ShopNest’s NotificationFactory creates Email or SMS senders based on user preference.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 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 }
Logging and caching decorators wrap IProductRepository so core SQL code stays clean.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 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(); }
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 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();
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 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); }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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
{
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."); }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: lice received: Hi Alice! How It Works:
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: daptee.SpecificRequest(), thus enabling compatibility between incompatible systems. Key Benefits of the Adapter Pattern:
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: How It Works: Follow:
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: And 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); } } And 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); } }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.