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 351–375 of 391

Popular tracks

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
Mid PDF
Log Level Enum:?

Answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error } What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns pr…

GoF Patterns Read answer
Mid PDF
Concrete Builder (MargheritaPizzaBuilder):?

The MargheritaPizzaBuilder is a concrete implementation of the IPizzaBuilder interface. It builds a specific type of pizza (Margherita in this case) by setting the dough, sauce, and adding toppings. The Build() method re…

GoF Patterns Read answer
Mid PDF
Concrete Implementations:?

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

GoF Patterns Read answer
Mid PDF
Adapter:?

The Adapter class implements the ITarget interface, and it wraps an instance of the Adaptee class. It delegates calls from Request() to the SpecificRequest() method of the Adaptee, making the two interfaces compatible. p…

GoF Patterns Read answer
Mid PDF
Abstract Product Interfaces (Button and Checkbox):?

The IButton and ICheckbox interfaces define the general contract for products. Each concrete product (e.g., WindowsButton, MacButton) will implement the Render method to display platform-specific UI elements. public inte…

GoF Patterns Read answer
Mid PDF
○ The Add class acts as a composite expression that adds the results of two?

Answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects…

GoF Patterns Read answer
Mid PDF
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 production Real-…

GoF Patterns Read answer
Mid PDF
Invoker (TextEditor): ○ The TextEditor class is the invoker that invokes commands. It holds a stack of commands (_commandHistory) and is responsible for executing

nd undoing commands. When a command is executed, it’s pushed onto the stack. The Undo() method pops the last executed command and undoes its ction. public class TextEditor { private readonly Stack<ICommand> _comman…

GoF Patterns Read answer
Mid PDF
Director (PizzaDirector): ○ The PizzaDirector class orchestrates the pizza building process. It uses a builder to construct a specific type of pizza (like Margherita) by calling the

ppropriate methods on the builder. It then returns the final product. public class PizzaDirector { private readonly IPizzaBuilder _builder; public PizzaDirector(IPizzaBuilder builder) => _builder = builder; public Piz…

GoF Patterns Read answer
Mid PDF
Usage: ○ In the Program class, you create an instance of Adaptee and then wrap it with an Adapter. The adapter.Request() call works seamlessly with the incompatible SpecificRequest() method, allowing the system to interact with the third-party library as if it were designed for the current system interface. class Program { static void Main() {

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…

GoF Patterns Read answer
Mid PDF
Product Class:?

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…

GoF Patterns Read answer
Mid PDF
Usage (Client Code):?

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…

GoF Patterns Read answer
Mid PDF
Concrete Creators (FileLoggerFactory and ConsoleLoggerFactory):?

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…

GoF Patterns Read answer
Mid PDF
Concrete Decorators (MilkDecorator and SugarDecorator):?

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…

GoF Patterns Read answer
Mid PDF
Invoker (TextEditor):?

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…

GoF Patterns Read answer

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

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

Answer: The LogLevel enum defines the different types of log messages (e.g., Info, Error). public enum LogLevel { Info, Error }

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

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

  • 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.");

}
Permalink & share

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

  • The Adapter class implements the ITarget interface, and it wraps an

instance of the Adaptee class. It delegates calls from Request() to the

SpecificRequest() method of the Adaptee, making the two interfaces

compatible.

public class Adapter : ITarget

private readonly Adaptee _adaptee;

public Adapter(Adaptee adaptee) => _adaptee = adaptee;

public void Request() => _adaptee.SpecificRequest();

Permalink & share

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

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

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

Answer: other expressions. It leverages the recursive nature of the Interpreter Pattern to evaluate complex expressions.

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:

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

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

}
}
}
Permalink & share

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

ppropriate methods on the builder. It then returns the final product.

public class PizzaDirector
{
private readonly IPizzaBuilder _builder;
public PizzaDirector(IPizzaBuilder builder) => _builder =

builder;

public Pizza ConstructMargheritaPizza()
{

_builder.SetDough("Thin Crust");

_builder.SetSauce("Tomato");

_builder.AddTopping("Mozzarella");

return _builder.Build();
}
}
Permalink & share

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. } }

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 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) =&gt; Name = name; }

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 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 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:

Permalink & share

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

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

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

  • 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

}
Permalink & share

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

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

Follow:

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