Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
The singleton instance is created when the class is loaded, guaranteeing thread safety without locking. However, it may have a slight performance overhead due to the instance being created regardless of whether it is nee…
Answer: When there is a need to store and share global configuration settings across the application (e.g., database connection strings, file paths, API keys). What interviewers expect A clear definition tied to GoF Patt…
The Singleton Pattern ensures that a class has only one instance, and it provides a global access point to that instance. This is especially useful when managing resources that should be shared across the application, su…
Answer: The Singleton class (ConfigurationManager) only allows one instance to be created. The instance is stored in the static _instance field, ensuring that only one object exists. What interviewers expect A clear defi…
The ConfigurationManager class is designed to ensure that there is only one instance of it throughout the application. The Instance property handles the lazy initialization of the singleton instance, ensuring that it's o…
Answer: A virtual proxy can be used to load large images or videos on-demand, especially when dealing with high-resolution media files that could be costly to load upfront. What interviewers expect A clear definition tie…
Answer: Used to delay the creation or initialization of an expensive object until it is actually needed, like the ProxyImage example above. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four…
Answer: The instance is created only when needed, reducing the overhead of initialization when the object is not used. This ensures that resources are used efficiently. What interviewers expect A clear definition tied to…
Answer: The client interacts with the proxy (ProxyImage), which implements the same interface (IImage) as the real subject (RealImage). What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Pat…
Answer: This is the common interface that both the real object (RealImage) and the proxy object (ProxyImage) implement. It defines the method Display() that both concrete classes must implement. public interface IImage {…
The example above demonstrates shallow cloning, where only the primitive properties are copied. If the object contains references to other objects (e.g., arrays, lists), you may need to implement deep cloning to ensure t…
Answer: Cloning objects is often more efficient than creating new ones from scratch, especially when the object is complex or expensive to create. This can be particularly useful in performance-sensitive applications lik…
Answer: This interface defines the Clone() method that will be used to create a copy of an object. Any class that needs to be cloned must implement this interface. What interviewers expect A clear definition tied to GoF…
Answer: A news website where multiple users subscribe to receive notifications when new articles or breaking news are published. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns p…
Answer: If the object being cloned is very large or complex, cloning might introduce performance overhead. You should evaluate the cost-benefit ratio of cloning versus object creation. Real-Time Use Case Examples: What i…
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…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
thread safety without locking. However, it may have a slight performance
overhead due to the instance being created regardless of whether it is
needed.
public class Singleton
{
private static readonly Singleton _instance = new Singleton();
private Singleton() { }
public static Singleton Instance => _instance;
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: When there is a need to store and share global configuration settings across the application (e.g., database connection strings, file paths, API keys).
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
provides a global access point to that instance. This is especially useful when
managing resources that should be shared across the application, such as
configuration settings, logging, or database connections.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The Singleton class (ConfigurationManager) only allows one instance to be created. The instance is stored in the static _instance field, ensuring that only one object exists.
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
instance of it throughout the application.
ensuring that it's only created once and then reused.
public class ConfigurationManager
{
private static ConfigurationManager _instance;
private static readonly object _lock = new object(); // Lock
for thread safety
private ConfigurationManager() { } // Private constructor to
prevent instantiation
public static ConfigurationManager Instance
{
get
{
lock (_lock) // Ensure thread safety
{
return _instance ??= new ConfigurationManager(); //
Lazy initialization
}
}
}
public string GetSetting(string key) => "some value"; // Example
method to return a setting
}
directly. This ensures that the class cannot be instantiated more than once.
ConfigurationManager. It uses lazy initialization to create the instance
only when it's first needed.
thread-safe, preventing multiple threads from creating multiple instances at
the same time in a multithreaded environment.
ensuring that the instance is created only once and reused thereafter.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: A virtual proxy can be used to load large images or videos on-demand, especially when dealing with high-resolution media files that could be costly to load upfront.
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: Used to delay the creation or initialization of an expensive object until it is actually needed, like the ProxyImage example above.
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 instance is created only when needed, reducing the overhead of initialization when the object is not used. This ensures that resources are used efficiently.
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 client interacts with the proxy (ProxyImage), which implements the same interface (IImage) as the real subject (RealImage).
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: This is the common interface that both the real object (RealImage) and the proxy object (ProxyImage) implement. It defines the method Display() that both concrete classes must implement. public interface IImage { void Display(); }
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
properties are copied. If the object contains references to other objects (e.g.,
arrays, lists), you may need to implement deep cloning to ensure that
referenced objects are also cloned, not just referenced.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: Cloning objects is often more efficient than creating new ones from scratch, especially when the object is complex or expensive to create. This can be particularly useful in performance-sensitive applications like games or simulations.
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: This interface defines the Clone() method that will be used to create a copy of an object. Any class that needs to be cloned must implement this interface.
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: A news website where multiple users subscribe to receive notifications when new articles or breaking news are published.
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: If the object being cloned is very large or complex, cloning might introduce performance overhead. You should evaluate the cost-benefit ratio of cloning versus object creation. Real-Time Use Case Examples:
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 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.