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 401–425 of 456

Career & HR topics

By tech stack

Mid PDF
Client Code:?

The client code does not need to know which logger is being used. It interacts with the factory (e.g., ConsoleLoggerFactory), which produces the desired logger. This decouples the client code from the concrete logging cl…

GoF Patterns Read answer
Mid PDF
Banking Software:?

Answer: In a banking application, a facade could simplify processes such as transferring funds, managing accounts, and checking balances, so that users don’t need to manually handle every step of the transaction. Improve…

GoF Patterns Read answer
Mid PDF
Reduced Dependencies:?

Answer: Clients don’t need to know about the specific classes that make up the subsystem. The facade hides this information, reducing dependencies and improving modularity. Real-Time Use Case Examples: What interviewers…

GoF Patterns Read answer
Mid PDF
Streaming Services:?

Answer: The Decorator Pattern can be used to extend the functionality of media streaming services. For example, you could decorate a base video stream to include ads, subtitles, or additional features like HD quality. Im…

GoF Patterns Read answer
Mid PDF
Dynamic Behavior Addition:?

The beauty of the Decorator Pattern is that new features (like milk or sugar) can be added dynamically, without changing the original SimpleCoffee class. You can stack decorators as needed, allowing for flexible and exte…

GoF Patterns Read answer
Mid PDF
File System Operations:?

Operations like searching for a file or calculating the total size of a directory could be added to the IFileSystemComponent interface and implemented by both files and directories. Visual Diagram: Here's a simple visual…

GoF Patterns Read answer
Mid PDF
Simplifies Client Code:?

The client code (in this case, the Program class) doesn’t need to worry about whether a component is a file or a directory. It can just call ShowInfo() on any component and let the pattern take care of the rest. Follow:…

GoF Patterns Read answer
Mid PDF
Recursive Structure:?

The ShowInfo() method in Directory calls ShowInfo() on all its child components. This is where the recursive nature of the Composite Pattern comes into play. It doesn’t matter whether the child is a File or another Direc…

GoF Patterns Read answer
Mid PDF
Queue of Requests:?

Answer: The Command Pattern allows commands to be queued for execution, making it suitable for scenarios where requests need to be delayed or processed sequentially, such as in transaction management or job scheduling. I…

GoF Patterns Read answer
Mid PDF
Flexible and Scalable:?

The pattern can be easily extended to include more handlers, which means it can scale well as the number of log levels (or other request types) grows. Improvement Suggestions: Add More Log Levels: Follow: You could add a…

GoF Patterns Read answer
Mid PDF
Reduces Code Duplication:?

You don’t need to re-implement the drawing logic for each new shape. Instead, you can simply reuse the same drawing API for multiple shapes. Follow: Improvement Suggestions: Add More Shapes: To extend the pattern, you ca…

GoF Patterns Read answer
Mid PDF
UI Event Handling: ○ In GUI systems, UI components (like buttons or text boxes) can be considered observers that listen to changes or events (like button clicks) from

user interface. Visual Diagram: +------------------+ +-------------------+ | NewsPublisher |-------| NewsSubscriber | | (Subject) | | (Observer) | +------------------+ +-------------------+ | | | Subscribe/Unsubscribe |…

GoF Patterns Read answer
Mid PDF
Usage (Client Code): ● In the Main method, a NewsPublisher is created, along with two subscribers: Alice?

nd Bob. The subscribers are subscribed to the publisher. When the publisher sends out a notification (Notify()), all subscribers are automatically notified and updated with the latest news. class Program { static void Ma…

GoF Patterns Read answer
Mid PDF
Decorator (CoffeeDecorator): ○ The CoffeeDecorator class is an abstract class that implements the ICoffee interface and holds a reference to an ICoffee object. This class

llows 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…

GoF Patterns Read answer
Mid PDF
Receiver (Document): ○ The Document class represents the receiver of the command. It contains the?

ctual operations for adding and removing text from the document. The ddText and RemoveText methods manipulate the internal content (a StringBuilder). public class Document { private readonly StringBuilder _content = new…

GoF Patterns Read answer
Mid PDF
UI Event Handling:?

In GUI systems, UI components (like buttons or text boxes) can be considered observers that listen to changes or events (like button clicks) from a user interface. Visual Diagram: +------------------+ +------------------…

GoF Patterns Read answer
Mid PDF
Colleague (User):?

The User class represents a user in the chat application. Each user has a name and a reference to the mediator. When a user wants to send a message, they call Send() on the mediator, which then sends the message to all o…

GoF Patterns Read answer
Mid PDF
Uniform Access:?

Answer: The Iterator Pattern provides a consistent and uniform way to access elements of the collection, regardless of the underlying structure of the collection. Real-Time Use Case Examples: What interviewers expect A c…

GoF Patterns Read answer
Mid PDF
Concrete Iterator (ProductIterator):?

The ProductIterator class implements the IIterator<Product> interface and keeps track of the current position in the ProductCollection. It knows how to traverse the collection, check if there’s a next item (HasNext…

GoF Patterns Read answer
Mid PDF
Non-terminal Expression (Add):?

Answer: The Add class is a non-terminal expression. It takes two other expressions (leftExpression and rightExpression) and computes their sum. Non-terminal expressions represent operations that combine multiple sub-expr…

GoF Patterns Read answer
Mid PDF
Usage (Main Program):?

In the client code, we create a CharacterFactory instance to manage the characters. We then iterate over the text "Hello World", requesting a Character object for each character. The flyweight objects are reused, reducin…

GoF Patterns Read answer
Mid PDF
Creator (LoggerFactory):?

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…

GoF Patterns Read answer
Mid PDF
Decorator (CoffeeDecorator):?

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 t…

GoF Patterns Read answer
Mid PDF
Composite (Directory):?

The Directory class is a composite node in the tree structure. It can contain multiple IFileSystemComponent objects (both files and subdirectories). The ShowInfo() method displays the directory’s name and recursively cal…

GoF Patterns Read answer
Mid PDF
Receiver (Document):?

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 StringBui…

GoF Patterns Read answer

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

  • The client code does not need to know which logger is being used. It interacts

with the factory (e.g., ConsoleLoggerFactory), which produces the

desired logger. This decouples the client code from the concrete logging

classes, promoting flexibility and scalability.

Key Benefits of the Factory Method Pattern:

Permalink & share

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

Answer: In a banking application, a facade could simplify processes such as transferring funds, managing accounts, and checking balances, so that users don’t need to manually handle every step of the transaction. Improvement Suggestions:

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: Clients don’t need to know about the specific classes that make up the subsystem. The facade hides this information, reducing dependencies and improving modularity. Real-Time Use Case Examples:

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 Decorator Pattern can be used to extend the functionality of media streaming services. For example, you could decorate a base video stream to include ads, subtitles, or additional features like HD quality. Improvement Suggestions:

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 beauty of the Decorator Pattern is that new features (like milk or sugar)

can be added dynamically, without changing the original SimpleCoffee

class. You can stack decorators as needed, allowing for flexible and

extensible object behavior at runtime.

Key Benefits of the Decorator Pattern:

Permalink & share

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

  • Operations like searching for a file or calculating the total size of a directory

could be added to the IFileSystemComponent interface and implemented

by both files and directories.

Visual Diagram:

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

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

| IFileSystemComponent |

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

/ \

/ \

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

| File | | Directory |

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

/ \

/ \

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

| File | | Directory |

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

  • File and Directory both implement IFileSystemComponent.
  • A Directory can contain multiple File objects or other Directory objects.

Conclusion:

The Composite Pattern is an effective design pattern for dealing with tree-like structures,

where individual objects and composites need to be treated uniformly. In real-time

applications like file systems, graphic design tools, and organizational hierarchies, this

pattern simplifies the client code and allows for flexible and scalable solutions. By using this

Follow:

pattern, you can easily manage complex structures and extend them with new types of

components as your system grows.

Decorator Pattern: Real-Time Example - Enhancing a Coffee Order

Scenario:

The Decorator Pattern is used to add new behaviors or responsibilities to objects

dynamically without affecting the behavior of other objects in the system. It’s perfect when

you want to extend or change the functionality of an object at runtime without altering its

original code.

Use Case:

A common example is a coffee order where you can add extra features such as milk, sugar,

or even whipped cream to a basic coffee without modifying the original Coffee class.

Code Explanation:

Permalink & share

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

  • The client code (in this case, the Program class) doesn’t need to worry about

whether a component is a file or a directory. It can just call ShowInfo() on

any component and let the pattern take care of the rest.

Follow:

Real-Time Use Case Example:

Permalink & share

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

  • The ShowInfo() method in Directory calls ShowInfo() on all its child

components. This is where the recursive nature of the Composite Pattern

comes into play. It doesn’t matter whether the child is a File or another

Directory; both types implement the ShowInfo() method, and the

directory simply iterates over its children.

Key Benefits of the Composite Pattern:

Permalink & share

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

Answer: The Command Pattern allows commands to be queued for execution, making it suitable for scenarios where requests need to be delayed or processed sequentially, such as in transaction management or job scheduling. Improvement Suggestions:

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 pattern can be easily extended to include more handlers, which means it

can scale well as the number of log levels (or other request types) grows.

Improvement Suggestions:

  • Add More Log Levels:

Follow:

  • You could add additional log levels such as Warning, Debug, or Fatal,

each handled by its own specific logger. You would just need to create new

concrete handlers for these levels.

  • Logging to Different Destinations:
  • Each logger could be extended to not just print to the console, but also log to

files, databases, or remote servers. This way, the Chain of Responsibility

could support more complex logging systems with different outputs for each

level.

  • Adding a Default Handler:
  • If no handler in the chain can process a message, it might be useful to have a

default handler (such as a DefaultLogger) that logs an unknown

message or performs some fallback action.

Real-Time Use Case Example:

The Chain of Responsibility Pattern is often used in real-time systems like:

  • Logging systems, where you need to handle messages at various levels (Info,

Error, Warning).

  • Event handling systems, where each handler deals with different types of events

and either processes or passes them on.

  • Request handling pipelines in web servers, where requests pass through multiple

stages, and each stage processes the request in a specific way (e.g., authentication,

authorization, logging, validation).

Visual Diagram:

Here’s a simple visual diagram to understand the Chain of Responsibility Pattern:

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

| InfoLogger | <-- Handles LogLevel.Info

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

Follow:

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

| ErrorLogger | <-- Handles LogLevel.Error

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

(End of Chain)

The Chain of Responsibility Pattern is a powerful way to handle requests that need to be

processed by multiple handlers, each responsible for a specific part of the process. It is

especially useful when you have a sequence of operations (like logging, event handling, or

request processing) that may vary based on context.

Command Pattern: Real-Time Example - Undo Functionality in a Text

Editor

Scenario:

In a text editor, you often need the ability to undo actions (like adding or removing text) to

revert the document to its previous state. The Command Pattern is an excellent choice for

implementing undo functionality. This pattern encapsulates requests as objects, allowing for

parameterization of clients with queues, requests, and operations. It decouples the sender of

the request from the object that processes the request, making it easier to manage actions

and undo operations.

Code Explanation:

Permalink & share

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

  • You don’t need to re-implement the drawing logic for each new shape.

Instead, you can simply reuse the same drawing API for multiple shapes.

Follow:

Improvement Suggestions:

  • Add More Shapes:
  • To extend the pattern, you can introduce additional shape classes like

Rectangle or Triangle, and have them use the same drawing API to

render their specific shapes.

  • Introduce More Drawing APIs:
  • As the application grows, you could add more concrete implementations of

IDrawingAPI for different rendering libraries, allowing the user to select their

preferred drawing style or technology.

  • Performance Optimization:
  • If your drawing application needs to optimize performance (e.g., when

rendering complex or large scenes), you could implement caching strategies

in your drawing APIs or leverage lazy initialization.

Real-Time Use Case Example:

The Bridge Pattern is particularly useful when building graphics software, drawing

applications, or game engines where you may need to render shapes in various styles. For

instance:

  • A drawing application that supports multiple rendering backends (e.g., OpenGL,

DirectX, or HTML Canvas).

  • A game engine where you have various game objects (e.g., players, enemies) that

need to be drawn using different rendering techniques.

Visual Diagram:

Here’s a simple visual diagram to understand the Bridge Pattern:

Abstraction (Shape) --> IDrawingAPI (Implementation)

| |

v v

Follow:

Refined Abstraction (Circle) --> Concrete Implementations

(DrawingAPI1, DrawingAPI2)

Builder Pattern: Real-Time Example - Building a Custom Pizza

Scenario:

Imagine you're building a pizza ordering system that allows customers to customize their

pizzas with different dough types, sauces, and toppings. The Builder Pattern is a perfect fit

for such use cases where you need to create complex objects step by step, each with

various configurations or options.

The Builder Pattern separates the construction of an object from its representation. This

means the same construction process can create different variations of an object. In this

case, the pattern allows for building different types of pizzas (e.g., Margherita, Pepperoni,

Veggie) with various ingredients.

Code Explanation:

Permalink & share

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

user interface.

Visual Diagram:

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

| NewsPublisher |-------| NewsSubscriber |

| (Subject) | | (Observer) |

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

| |

| Subscribe/Unsubscribe | Update

v v

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

| NewsPublisher | | NewsSubscriber |

| (Subject) |-------| (Observer) |

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

Conclusion:

The Observer Pattern is a powerful and flexible design pattern for building systems where

objects need to be notified of changes to another object's state. It's particularly useful in

event-driven architectures, where one action (such as publishing an article, changing a stock

price, or a weather update) triggers multiple reactions (notifications to subscribers). The

pattern promotes loose coupling and ensures that your system remains scalable,

maintainable, and responsive to changes in state.

Prototype Pattern: Cloning Complex Objects

Definition:

The Prototype Pattern is a creational design pattern that allows you to create new objects

by copying an existing object, known as the "prototype." This pattern is particularly useful

when the cost of creating an object from scratch is expensive or complex, and you want to

reuse an existing object as the prototype to create new instances.

Use Case:

typical use case for the Prototype Pattern is cloning complex objects, such as game

characters with various attributes (e.g., health, weapons, inventory), where creating new

objects from scratch can be time-consuming. Instead of rebuilding objects from the ground

up, you can clone an existing object and modify it as necessary.

Code Breakdown:

Permalink & share

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

nd Bob. The subscribers are subscribed to the publisher. When the publisher sends

out a notification (Notify()), all subscribers are automatically notified and updated

with the latest news.

class Program
{

static void Main()

{
var publisher = new NewsPublisher();
var subscriber1 = new NewsSubscriber("Alice");
var subscriber2 = new NewsSubscriber("Bob");

publisher.Subscribe(subscriber1);

publisher.Subscribe(subscriber2);

publisher.Notify("Breaking News: Observer Pattern in C#!");

}
}

Output:

lice received news: Breaking News: Observer Pattern in C#!

Bob received news: Breaking News: Observer Pattern in C#!

  • How It Works:
Permalink & share

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

llows 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();
}
Permalink & share

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

ctual operations for adding and removing text from the document. The

ddText 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();
}
Permalink & share

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

  • In GUI systems, UI components (like buttons or text boxes) can be

considered observers that listen to changes or events (like button clicks) from

a user interface.

Visual Diagram:

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

| NewsPublisher |-------| NewsSubscriber |

| (Subject) | | (Observer) |

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

| |

| Subscribe/Unsubscribe | Update

v v

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

| NewsPublisher | | NewsSubscriber |

Follow:

| (Subject) |-------| (Observer) |

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

Conclusion:

The Observer Pattern is a powerful and flexible design pattern for building systems where

objects need to be notified of changes to another object's state. It's particularly useful in

event-driven architectures, where one action (such as publishing an article, changing a stock

price, or a weather update) triggers multiple reactions (notifications to subscribers). The

pattern promotes loose coupling and ensures that your system remains scalable,

maintainable, and responsive to changes in state.

Prototype Pattern: Cloning Complex Objects

Definition:

The Prototype Pattern is a creational design pattern that allows you to create new objects

by copying an existing object, known as the "prototype." This pattern is particularly useful

when the cost of creating an object from scratch is expensive or complex, and you want to

reuse an existing object as the prototype to create new instances.

Use Case:

A typical use case for the Prototype Pattern is cloning complex objects, such as game

characters with various attributes (e.g., health, weapons, inventory), where creating new

objects from scratch can be time-consuming. Instead of rebuilding objects from the ground

up, you can clone an existing object and modify it as necessary.

Code Breakdown:

Permalink & share

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

  • The User class represents a user in the chat application. Each user has a

name and a reference to the mediator.

  • When a user wants to send a message, they call Send() on the mediator,

which then sends the message to all other registered users.

  • Users only interact with the mediator, and not with each other directly.
public class User
{
private readonly string _name;
private readonly IChatMediator _mediator;
public User(string name, IChatMediator mediator)
{
_name = name;
_mediator = mediator;

_mediator.RegisterUser(this); // Register the user with the

mediator

}
public void Send(string message) =>

_mediator.SendMessage(message, this);

public void Receive(string message) =>

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

}
Permalink & share

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

Answer: The Iterator Pattern provides a consistent and uniform way to access elements of the collection, regardless of the underlying structure of the collection. Real-Time Use Case Examples:

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 ProductIterator class implements the IIterator<Product>
interface and keeps track of the current position in the

ProductCollection. It knows how to traverse the collection, check if

there’s a next item (HasNext()), and return the next item (Next()).

Permalink & share

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

Answer: The Add class is a non-terminal expression. It takes two other expressions (leftExpression and rightExpression) and computes their sum. Non-terminal expressions represent operations that combine multiple sub-expressions.

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

  • In the client code, we create a CharacterFactory instance to manage the

characters. We then iterate over the text "Hello World", requesting a

Character object for each character.

  • The flyweight objects are reused, reducing memory consumption.
class Program
{

static void Main()

{
var factory = new CharacterFactory();
string text = "Hello World";
foreach (var c in text)
{
var character = factory.GetCharacter(c);

character.Display(0, 0); // Simplified position for this

example

}
}
}
Permalink & share

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

  • 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();
}
Permalink & share

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

  • 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();

Permalink & share

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

  • The Directory class is a composite node in the tree structure. It can

contain multiple IFileSystemComponent objects (both files and

subdirectories). The ShowInfo() method displays the directory’s name and

recursively calls ShowInfo() on its children (whether they are files or

subdirectories).

Permalink & share

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

  • 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

Follow:

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();

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