Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Answer: The NewsPublisher class acts as the subject in the Observer Pattern. It maintains a list of IObserver instances (subscribers) and provides methods to add (Subscribe), remove (Unsubscribe), and notify them (Notify…
This interface defines methods for subscribing, unsubscribing, and notifying observers. The subject manages a list of observers and notifies them when there is an update. public interface INewsPublisher Follow: void Subs…
In a text editor (such as Microsoft Word or Notepad), users can press Ctrl + Z to undo the most recent changes. Each time the user types, the editor saves a snapshot of the text as a Memento. Pressing Ctrl + Z restores t…
Answer: If the object’s state is large or changes frequently, the Memento Pattern can result in significant memory usage, as you need to store many copies of the state (each memento). What interviewers expect A clear def…
The Memento Pattern preserves encapsulation because the state is stored in the Memento object, and the TextEditor is not exposed to direct manipulation of its internal state. The only way to change or access the state is…
Answer: The TextEditor is the originator of the state. It holds the text that changes over time and can save and restore its state using mementos. What interviewers expect A clear definition tied to GoF Patterns in Gang…
The TextMemento class holds the state of the TextEditor object. It only exposes the state (the text content) and doesn’t allow direct manipulation of that state. The Memento is a snapshot of the internal state of the Tex…
Since the mediator handles all interactions between objects, it becomes a critical part of the system. If the mediator fails, the entire communication system breaks down. This could be mitigated by introducing fault tole…
Answer: A classic example of the Mediator Pattern is a chat application, where the mediator is responsible for sending messages between users. It ensures that messages are routed correctly without the users needing to kn…
The Observer Pattern promotes loose coupling between the subject and the observers. The subject does not know about the specific observers, only that they implement the IObserver interface. This makes the system more fle…
The mediator manages communication between the users. It maintains a list of all users and broadcasts messages to all other users when one user sends a message. This keeps the users from directly knowing about each other…
The IChatMediator interface defines two key operations: ■ SendMessage(string message, User user): Sends a message from a user to all other registered users. ■ RegisterUser(User user): Registers users with the mediator so…
Answer: The Iterator Pattern can be extended to support reverse iteration or provide additional functionality like removing items during iteration. What interviewers expect A clear definition tied to GoF Patterns in Gang…
The Iterator Pattern is commonly used when working with product lists, customer lists, or any other collection where you need to iterate over items sequentially. For instance, in an e-commerce application, you might use…
Answer: The IIterator<T> interface defines the contract for all iterators. It ensures that all iterators implement the basic functionality of checking for the next element (HasNext()) and returning the next…
Answer: For more complex grammars, the interpreter may become inefficient. Optimizations such as memoization (caching results) can be used to avoid redundant evaluations, particularly for recursive expressions. What inte…
Calculator applications that need to parse and evaluate mathematical expressions like 5 + 3 * 2 can leverage the Interpreter Pattern to handle different operators and operands. Each part of the expression (numbers, opera…
Answer: The Interpreter Pattern is ideal for scenarios where the grammar is complex and subject to change. By defining expressions as objects, it’s easy to extend or modify the grammar without affecting other parts of th…
Answer: The IExpression interface defines the contract for all expressions in the grammar, allowing them to be interpreted (evaluated). Every class that implements this interface will provide its own interpretation logic…
If the number of unique characters or objects grows significantly, the CharacterFactory can implement cache management strategies like LRU (Least Recently Used) or FIFO (First In, First Out) to evict older or unused obje…
Many games display large amounts of text (e.g., in dialogues, menus, or scores). Using the Flyweight Pattern, you can optimize memory usage by reusing the same Character objects for common letters or symbols, rather than…
The Character class holds the intrinsic state (the character symbol), which is shared across all instances. This makes it an ideal candidate for the Flyweight Pattern because multiple characters (e.g., 'H', 'e', 'l') may…
This class represents the Flyweight object. It contains the intrinsic state that is shared across multiple instances (the character symbol, in this case), and it provides a Display method to show the character's symbol a…
In a more advanced system, you could dynamically choose which factory to use based on external configurations, like settings or environment variables. This would enable the system to switch between different logging mech…
As mentioned, logging systems often use the Factory Method to allow different log outputs. For example, a logging framework can provide loggers that write to the console, files, databases, or cloud services, with the use…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The NewsPublisher class acts as the subject in the Observer Pattern. It maintains a list of IObserver instances (subscribers) and provides methods to add (Subscribe), remove (Unsubscribe), and notify them (Notify).
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
observers. The subject manages a list of observers and notifies them when there is
an update.
public interface INewsPublisher
Follow:
void Subscribe(IObserver observer);
void Unsubscribe(IObserver observer);
void Notify(string news);
Gang of Four Patterns Design Patterns in C# · GoF Patterns
to undo the most recent changes. Each time the user types, the editor saves
a snapshot of the text as a Memento. Pressing Ctrl + Z restores the text to its
previous state.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: If the object’s state is large or changes frequently, the Memento Pattern can result in significant memory usage, as you need to store many copies of the state (each memento).
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
in the Memento object, and the TextEditor is not exposed to direct
manipulation of its internal state. The only way to change or access the state
is through well-defined methods (Save and Restore).
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The TextEditor is the originator of the state. It holds the text that changes over time and can save and restore its state using mementos.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
the state (the text content) and doesn’t allow direct manipulation of that state.
public class TextMemento
public string Text { get; }
public TextMemento(string text) => Text = text;
Follow:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
critical part of the system. If the mediator fails, the entire communication
system breaks down. This could be mitigated by introducing fault tolerance or
redundancy in the mediator.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: A classic example of the Mediator Pattern is a chat application, where the mediator is responsible for sending messages between users. It ensures that messages are routed correctly without the users needing to know about each other.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
observers. The subject does not know about the specific observers, only that
they implement the IObserver interface. This makes the system more
flexible and easier to maintain.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
of all users and broadcasts messages to all other users when one user sends
a message.
loose coupling.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
■ SendMessage(string message, User user): Sends a
message from a user to all other registered users.
■ RegisterUser(User user): Registers users with the mediator so
they can send and receive messages.
public interface IChatMediator
{
void SendMessage(string message, User user);
void RegisterUser(User user);
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The Iterator Pattern can be extended to support reverse iteration or provide additional functionality like removing items during iteration.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
customer lists, or any other collection where you need to iterate over items
sequentially. For instance, in an e-commerce application, you might use an
iterator to list products, iterate through available categories, or paginate
results.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The IIterator<T> interface defines the contract for all iterators. It ensures that all iterators implement the basic functionality of checking for the next element (HasNext()) and returning the next element (Next()).
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: For more complex grammars, the interpreter may become inefficient. Optimizations such as memoization (caching results) can be used to avoid redundant evaluations, particularly for recursive expressions.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
expressions like 5 + 3 * 2 can leverage the Interpreter Pattern to handle
different operators and operands. Each part of the expression (numbers,
operators) is represented as an object that can be evaluated.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The Interpreter Pattern is ideal for scenarios where the grammar is complex and subject to change. By defining expressions as objects, it’s easy to extend or modify the grammar without affecting other parts of the system.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The IExpression interface defines the contract for all expressions in the grammar, allowing them to be interpreted (evaluated). Every class that implements this interface will provide its own interpretation logic.
In a production Gang of Four Patterns application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
CharacterFactory can implement cache management strategies like
LRU (Least Recently Used) or FIFO (First In, First Out) to evict older or
unused objects and maintain memory efficiency.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
scores). Using the Flyweight Pattern, you can optimize memory usage by
reusing the same Character objects for common letters or symbols, rather
than creating a new object for each instance.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
is shared across all instances. This makes it an ideal candidate for the
Flyweight Pattern because multiple characters (e.g., 'H', 'e', 'l') may appear
many times in the same text, but they only need one Character object for
the symbol.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
is shared across multiple instances (the character symbol, in this case), and it
provides a Display method to show the character's symbol at a particular
coordinate.
public class Character
{
private readonly char _symbol;
public Character(char symbol) => _symbol = symbol;
public void Display(int x, int y) =>
Console.WriteLine($"Character: {_symbol} at ({x}, {y})");
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
use based on external configurations, like settings or environment variables.
This would enable the system to switch between different logging
mechanisms or database connections without recompiling the application.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
different log outputs. For example, a logging framework can provide loggers
that write to the console, files, databases, or cloud services, with the user
choosing the appropriate logger type via a factory.