Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4616 total questions 4516 technical 100 career & HR 4346 from PDF library

Showing 326–350 of 456

Career & HR topics

By tech stack

Mid PDF
Use Dependency Injection:?

Instead of directly instantiating the factory within the client code, you could use dependency injection to pass the correct factory implementation into the client code. This would make the code even more flexible and te…

GoF Patterns Read answer
Mid PDF
Document Generators:?

A document generation system might have different types of document formats, such as PDF, Word, or HTML. A Factory Method can be used to create the appropriate document generator based on user input, allowing for flexibl…

GoF Patterns Read answer
Mid PDF
Products (FileLogger, ConsoleLogger):?

Answer: The ILogger interface is implemented by the concrete classes FileLogger and ConsoleLogger. These classes define how the log message will be handled, either by writing to a file or outputting to the console. What…

GoF Patterns Read answer
Mid PDF
Concrete Products (FileLogger and ConsoleLogger):?

Follow: These classes implement the ILogger interface, defining how the messages are logged (either to a file or the console). FileLogger: public class FileLogger : ILogger public void Log(string message) => Console.W…

GoF Patterns Read answer
Mid PDF
Exception Handling:?

The facade can be enhanced with better exception handling. For example, if a component fails (e.g., DVD player is missing), the facade could display a user-friendly message or take an appropriate action. Visual Diagram:…

GoF Patterns Read answer
Mid PDF
Financial Systems:?

A Facade Pattern can be used in financial systems where complex operations like credit checks, account updates, and transaction processing are abstracted into a simplified process, allowing users to perform transactions…

GoF Patterns Read answer
Mid PDF
Readability and Maintenance:?

Answer: The Facade makes the system more readable. If the subsystem's complexity changes, the facade can be updated without affecting the client code. What interviewers expect A clear definition tied to GoF Patterns in G…

GoF Patterns Read answer
Mid PDF
Simplified Interface:?

The Facade Pattern enables the user to work with a single entry point (i.e., the HomeTheaterFacade), which internally delegates tasks to the complex subsystem classes. This makes the system much easier to use while hidin…

GoF Patterns Read answer
Mid PDF
Facade (HomeTheaterFacade):?

The Facade class simplifies interactions with the subsystem by providing a unified interface for the user. It wraps the complex subsystem and provides higher-level methods that internally call the appropriate subsystem m…

GoF Patterns Read answer
Mid PDF
Dynamic Features:?

Add functionality to dynamically change the properties of the decorated object. For instance, you could add a feature to customize the size of the coffee (Small, Medium, Large) which would change both the cost and descri…

GoF Patterns Read answer
Mid PDF
Text Editors:?

Answer: In text editors, the Decorator Pattern could be used for adding formatting options to text (bold, italic, underline) dynamically, without needing separate classes for each combination of formatting. What intervie…

GoF Patterns Read answer
Mid PDF
Preservation of Core Class:?

Answer: The original SimpleCoffee class remains unchanged, which means you don’t need to touch existing code. The new functionality is added without altering or subclassing the core class. What interviewers expect A clea…

GoF Patterns Read answer
Mid PDF
Decorator Pattern:?

The CoffeeDecorator class is abstract, and all concrete decorators (MilkDecorator, SugarDecorator) extend this class. The decorator wraps the SimpleCoffee object (or other decorated objects) and enhances or alters its be…

GoF Patterns Read answer
Mid PDF
Concrete Component (SimpleCoffee):?

Answer: SimpleCoffee is the core object that implements ICoffee. It has a fixed price and a basic description. This is the base coffee that we will add features to dynamically. What interviewers expect A clear definition…

GoF Patterns Read answer
Mid PDF
Support for Metadata:?

Answer: You can extend the file system to support additional metadata for each file or directory, such as size, creation date, and file type. This could be added as properties in the File and Directory classes. What inte…

GoF Patterns Read answer
Mid PDF
Organization Structures:?

The Composite Pattern can also be used in organizational structures, where departments (composites) contain teams or employees (individuals), and both can be treated as "components" with a common interface for operations…

GoF Patterns Read answer
Mid PDF
Recursive Processing:?

Answer: The recursive structure makes it easy to manage hierarchical data. For example, when displaying the contents of a directory, you don’t need to worry about whether the child is a file or a subdirectory. What inter…

GoF Patterns Read answer
Mid PDF
Leaf (File):?

The File class represents the leaf in the tree structure. It is an individual component (a file) and implements the ShowInfo() method to display its details. public class File : IFileSystemComponent { private string _nam…

GoF Patterns Read answer
Mid PDF
Composite Commands:?

You can combine multiple commands into a composite command. For example, if the user performs a series of actions (like adding text, changing fonts, and changing colors), you can encapsulate all of those actions into a s…

GoF Patterns Read answer
Mid PDF
Extensibility:?

Answer: New types of loggers can be added in the future (e.g., DatabaseLogger, CloudLogger) by simply creating new factory subclasses without modifying existing client code. What interviewers expect A clear definition ti…

GoF Patterns Read answer
Mid PDF
Undo Mechanism:?

The TextEditor maintains a stack of executed commands. When the Undo() method is called, it pops the most recent command from the stack and calls its Undo() method, which reverts the action performed by the command (remo…

GoF Patterns Read answer
Mid PDF
Concrete Command (AddTextCommand):?

The AddTextCommand is a concrete implementation of the ICommand interface. It encapsulates the request to add text to the document. The Execute() method adds the specified text to the document, and the Undo() method remo…

GoF Patterns Read answer
Mid PDF
Passing Requests Along the Chain: ○ If a handler can't process a message, it passes the request along to the next handler in the chain (i.e., by calling NextLogger?

Answer: .LogMessage(...)). This continues until a handler processes the message or the chain is exhausted. Key Benefits of the Chain of Responsibility Pattern: What interviewers expect A clear definition tied to GoF Patt…

GoF Patterns Read answer
Mid PDF
Concrete Handlers:?

The InfoLogger and ErrorLogger are concrete handlers that implement the Logger class. Each handler checks if it can handle a particular log level (e.g., Info or Error). If it can, it processes the log; otherwise, it pass…

GoF Patterns Read answer
Mid PDF
Improved Maintainability:?

Since each handler is responsible for a specific task (in this case, logging a specific level of message), it’s easier to modify or extend the system. For example, adding a new log level (e.g., Debug) would only require…

GoF Patterns Read answer

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • Instead of directly instantiating the factory within the client code, you could

use dependency injection to pass the correct factory implementation into

the client code. This would make the code even more flexible and testable.

Visual Diagram:

+---------------------+

| LoggerFactory | <--- Abstract Factory

(Factory Method)

+---------------------+

+--------------------------+

| |

+-------------------+ +-------------------+

| FileLoggerFactory | | ConsoleLoggerFactory | <--- Concrete

Factories

+-------------------+ +-----------------------+

| |

+---------------+ +----------------+

| FileLogger | | ConsoleLogger | <--- Concrete

Products

Follow:

+---------------+ +----------------+

\ /

\ Client Code /

\_____________________/

Factory Interaction

  • The Factory Method pattern allows the client code to interact with the abstract

factory (LoggerFactory), which then returns the appropriate logger (FileLogger

or ConsoleLogger).

Conclusion:

The Factory Method Pattern offers a flexible and extensible solution for object creation,

especially in scenarios where the type of object to be created is determined at runtime. It

decouples the client code from specific classes, making it easier to extend and maintain.

Whether it's for logging systems, database connections, or UI components, this pattern

allows developers to create objects in a controlled and predictable manner, improving

scalability and maintainability.

Flyweight Pattern: Real-Time Example - Managing Graphic Objects in a

Game

Definition:

The Flyweight Pattern is designed to reduce the cost of creating and manipulating a large

number of similar objects. By sharing common parts of an object between multiple instances,

it saves memory and improves performance.

Use Case:

A typical use case for the Flyweight Pattern is in applications like games or text editors

that need to handle a large number of similar objects. For example, in a game with many

characters displayed on the screen, each character might be similar but would take up

unnecessary memory if each instance stored its own version of a character object. The

Flyweight pattern can be used to share the common properties (like the character symbol)

and only store unique ones (like the position).

Code Explanation:

Follow:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • A document generation system might have different types of document
formats, such as PDF, Word, or HTML. A Factory Method can be used to

create the appropriate document generator based on user input, allowing for

flexible document creation without hardcoding the specific document format

classes.
Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: The ILogger interface is implemented by the concrete classes FileLogger and ConsoleLogger. These classes define how the log message will be handled, either by writing to a file or outputting to the console.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Follow:

  • These classes implement the ILogger interface, defining how the messages

are logged (either to a file or the console).

FileLogger:

public class FileLogger : ILogger

public void Log(string message) => Console.WriteLine($"Logging

to file: {message}");

ConsoleLogger:

public class ConsoleLogger : ILogger

public void Log(string message) => Console.WriteLine($"Logging

to console: {message}");

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The facade can be enhanced with better exception handling. For example, if a

component fails (e.g., DVD player is missing), the facade could display a

user-friendly message or take an appropriate action.

Visual Diagram:

+-------------------------------------+

| HomeTheaterFacade | <-- Facade

(Simplified Interface)

+-------------------------------------+

/ \

/ \

+---------------+ +---------------+

| Amplifier | | DVD Player | <-- Subsystem

Classes

+---------------+ +---------------+

| |

(turn on, play movie) (play movie, etc.)

  • The Facade class provides a simplified interface (WatchMovie() and

EndMovie()) to the user.

  • Internally, it interacts with complex components (Amplifier, DVDPlayer) to achieve the

desired result.

Conclusion:

Follow:

The Facade Pattern is highly effective for simplifying complex systems by providing a

unified interface. In the case of a home theater system, it reduces the complexity of

managing multiple components and makes the system more user-friendly. Whether it’s home

entertainment, e-commerce systems, or banking software, the Facade Pattern is a valuable

design pattern for hiding complexity and improving usability.

Factory Method Pattern: Real-Time Example - Logging Framework

Definition:

The Factory Method Pattern defines an interface for creating objects, but allows

subclasses to alter the type of objects that will be created. This provides flexibility in creating

different types of objects while adhering to the same interface.

Use Case:

A common use case for the Factory Method Pattern is in logging frameworks. Such

frameworks can log messages to various destinations, like files, databases, or consoles. The

Factory Method allows the system to choose the appropriate logging mechanism

dynamically, based on configuration or user preferences, without tightly coupling the client

code to specific classes.

Code Explanation:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • A Facade Pattern can be used in financial systems where complex

operations like credit checks, account updates, and transaction processing

are abstracted into a simplified process, allowing users to perform

transactions without understanding the underlying complexities.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: The Facade makes the system more readable. If the subsystem's complexity changes, the facade can be updated without affecting the client code.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The Facade Pattern enables the user to work with a single entry point (i.e.,

the HomeTheaterFacade), which internally delegates tasks to the complex

subsystem classes. This makes the system much easier to use while hiding

unnecessary complexity.

Key Benefits of the Facade Pattern:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The Facade class simplifies interactions with the subsystem by providing a

unified interface for the user. It wraps the complex subsystem and provides

higher-level methods that internally call the appropriate subsystem methods.

public class HomeTheaterFacade
{
private readonly Amplifier _amplifier;
private readonly DVDPlayer _dvdPlayer;
public HomeTheaterFacade(Amplifier amplifier, DVDPlayer

dvdPlayer)

{
_amplifier = amplifier;
_dvdPlayer = dvdPlayer;
}
public void WatchMovie(string movie)
{

_amplifier.On();

_dvdPlayer.Play(movie);

}
public void EndMovie()
{

_amplifier.Off();

}
}
Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • Add functionality to dynamically change the properties of the decorated

object. For instance, you could add a feature to customize the size of the

coffee (Small, Medium, Large) which would change both the cost and

description.

Visual Diagram:

+-------------------------+

| ICoffee | <-- Component Interface

+-------------------------+

/ \

+-------------------------+

| SimpleCoffee | <-- Concrete Component (Core Coffee)

+-------------------------+

+---------------------+ +----------------------+

| CoffeeDecorator |<--- | MilkDecorator |

+---------------------+ +----------------------+

| |

Follow:

+---------------------+ +----------------------+

| SugarDecorator | <-- | WhippedCreamDecorator |

+---------------------+ +----------------------+

  • SimpleCoffee is the base coffee object.
  • MilkDecorator and SugarDecorator are decorators that extend the behavior of

SimpleCoffee.

Conclusion:

The Decorator Pattern provides a powerful and flexible way to extend the functionality of

objects at runtime. In real-time applications like customizing a coffee order, decorating UI

elements, or adding functionality to text, this pattern helps in achieving clean, modular, and

extensible code. You can add or remove features dynamically, ensuring that your base

classes remain unaltered and your system remains flexible for future extensions.

Facade Pattern: Real-Time Example - Simplifying a Home Theater

System

Definition:

The Facade Pattern provides a simplified interface to a complex subsystem, making it

easier for clients to interact with multiple components. It hides the complexity of the

subsystem and exposes only what is necessary, offering a higher-level interface to users.

Use Case:

A common example is a home theater system, where the user needs to interact with

multiple components like an amplifier, DVD player, or projector. The Facade Pattern

simplifies the process by providing a unified interface to these various components, making

the system easier to use.

Code Explanation:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: In text editors, the Decorator Pattern could be used for adding formatting options to text (bold, italic, underline) dynamically, without needing separate classes for each combination of formatting.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: The original SimpleCoffee class remains unchanged, which means you don’t need to touch existing code. The new functionality is added without altering or subclassing the core class.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The CoffeeDecorator class is abstract, and all concrete decorators

(MilkDecorator, SugarDecorator) extend this class. The decorator

wraps the SimpleCoffee object (or other decorated objects) and enhances

or alters its behavior, like adding extra cost or modifying the description.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: SimpleCoffee is the core object that implements ICoffee. It has a fixed price and a basic description. This is the base coffee that we will add features to dynamically.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: You can extend the file system to support additional metadata for each file or directory, such as size, creation date, and file type. This could be added as properties in the File and Directory classes.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The Composite Pattern can also be used in organizational structures, where

departments (composites) contain teams or employees (individuals), and both

can be treated as "components" with a common interface for operations like

calculating total salary or generating reports.

Improvement Suggestions:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: The recursive structure makes it easy to manage hierarchical data. For example, when displaying the contents of a directory, you don’t need to worry about whether the child is a file or a subdirectory.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The File class represents the leaf in the tree structure. It is an individual

component (a file) and implements the ShowInfo() method to display its

details.

public class File : IFileSystemComponent
{
private string _name;
public File(string name) => _name = name;
public void ShowInfo() => Console.WriteLine($"File: {_name}");
}
Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • You can combine multiple commands into a composite command. For

example, if the user performs a series of actions (like adding text, changing

fonts, and changing colors), you can encapsulate all of those actions into a

single composite command that can be undone in one step.

Real-Time Use Case Example:

The Command Pattern is often used in:

  • Text Editors: For implementing undo/redo functionality and user interactions.
  • Transaction Systems: Where each action can be encapsulated as a command, and

the entire system can be undone or redone.

  • GUI Frameworks: Buttons, sliders, and menu items can be mapped to commands,

allowing for consistent handling of actions across the UI.

  • Gaming Applications: Where player actions (e.g., moving, shooting) can be

encapsulated as commands and undone when necessary.

Follow:

Visual Diagram:

Here's a simple visual diagram to understand the Command Pattern:

+-----------------+ +---------------------+

+------------------+

| TextEditor | ---> | AddTextCommand | ---> |

Document |

| (Invoker) | | (Concrete Command) | |

(Receiver) |

+-----------------+ +---------------------+

+------------------+

| |

+-----------+

+-------------------+

| Undo | |

AddText / RemoveText |

+-----------+

+-------------------+

The Command Pattern provides a flexible and scalable way to handle requests in

object-oriented systems, especially when you need to manage complex workflows,

implement undo/redo functionality, or decouple senders from receivers.

Composite Pattern: Real-Time Example - Building a File System

Scenario:

The Composite Pattern is used when you need to treat individual objects and compositions

of objects uniformly. This is particularly useful when you have a hierarchical structure, like a

file system, where files and directories can be treated in a similar manner.

In a file system:

  • Files are the individual objects (leaves).

Follow:

  • Directories are composite objects that can contain files or other directories

(children).

This pattern helps to simplify the management of hierarchical structures, making it easier to

handle both individual items and collections of items in a unified way.

Code Explanation:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: New types of loggers can be added in the future (e.g., DatabaseLogger, CloudLogger) by simply creating new factory subclasses without modifying existing client code.

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The TextEditor maintains a stack of executed commands. When the

Undo() method is called, it pops the most recent command from the stack

and calls its Undo() method, which reverts the action performed by the

command (removes the last added text).

Key Benefits of the Command Pattern:

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The AddTextCommand is a concrete implementation of the ICommand
interface. It encapsulates the request to add text to the document.
  • The Execute() method adds the specified text to the document, and the

Undo() method removes that text.

public class AddTextCommand : ICommand
{
private readonly Document _document;
private readonly string _text;
public AddTextCommand(Document document, string text)
{
_document = document;
_text = text;
}
public void Execute() => _document.AddText(_text);
public void Undo() => _document.RemoveText(_text);
}
Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

Answer: .LogMessage(...)). This continues until a handler processes the message or the chain is exhausted. Key Benefits of the Chain of Responsibility Pattern:

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-world example

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.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Gang of Four Patterns architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • The InfoLogger and ErrorLogger are concrete handlers that implement

the Logger class. Each handler checks if it can handle a particular log level

(e.g., Info or Error). If it can, it processes the log; otherwise, it passes it along

to the next handler in the chain.

public class InfoLogger : Logger
{

protected override bool CanHandle(LogLevel level) => level ==

LogLevel.Info;

protected override void Handle(string message) =>

Console.WriteLine($"Info: {message}");

}
public class ErrorLogger : Logger
{

protected override bool CanHandle(LogLevel level) => level ==

LogLevel.Error;

protected override void Handle(string message) =>

Console.WriteLine($"Error: {message}");

}
Permalink & share

Gang of Four Patterns Design Patterns in C# · GoF Patterns

  • Since each handler is responsible for a specific task (in this case, logging a

specific level of message), it’s easier to modify or extend the system. For

example, adding a new log level (e.g., Debug) would only require creating a

new handler for that level without affecting existing code.

Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details