Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: The ISortStrategy interface defines a common method (Sort) that all concrete strategies must implement. This allows clients (in this case, the Sorter class) to work with any strategy that implements this in…
Short answer: The State Pattern introduces a separate class for each state, which can lead to an increase in the number of classes in the system. For systems with many states, this can cause complexity. Real-world exampl…
Short answer: When you have an object that can be in multiple predefined states and its behavior depends on the current state (e.g., traffic lights, order processing systems). Say this in the interview Define — one clear…
Short answer: The ITrafficLightState interface defines a method (Change) that allows the traffic light to transition between states (Red, Green, Yellow). Real-world example (ShopNest) Use a GoF pattern in ShopNest only w…
Short answer: The ITrafficLightState interface defines a method (Change) that allows the state to transition to another state. The method accepts a TrafficLight object as a parameter to facilitate the state change. publi…
Short answer: The Singleton can act as a global variable, which may make it harder to track state changes and can lead to issues with dependencies. Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it…
Short answer: 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 whe…
Short 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). Say this in the interview Define — one clear sentence…
Short answer: 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 a…
Short 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. Real-world example (ShopNest) U…
Short answer: The ConfigurationManager class is designed to ensure that there is only one instance of it throughout the application. Explain a bit more The Instance property handles the lazy initialization of the singlet…
Short 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. Real-world example (ShopNest) Use a GoF p…
Short answer: Used to delay the creation or initialization of an expensive object until it is actually needed, like the ProxyImage example above. Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it r…
Short answer: The proxy allows you to delay the creation of resource-intensive objects (like loading an image) until it's actually needed, optimizing resource usage. Real-world example (ShopNest) Use a GoF pattern in Sho…
Short answer: The client interacts with the proxy (ProxyImage), which implements the same interface (IImage) as the real subject (RealImage). Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it remov…
Short 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 II…
Short answer: In a role-playing game (RPG), characters or enemies can be cloned from a prototype template (e.g., an "Archer" prototype) and customized with different attributes (e.g., health, attack power) to c…
Short answer: 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 cloni…
Short 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 applicatio…
Short answer: This interface defines the Clone() method that concrete prototypes must implement. This method returns a new object that is a copy of the current object. public interface ICloneable Example code { ICloneabl…
Short answer: A news website where multiple users subscribe to receive notifications when new articles or breaking news are published. Real-world example (ShopNest) Use a GoF pattern in ShopNest only when it removes dupl…
Short answer: If there are a large number of observers or if the state changes frequently, the Observer Pattern can lead to performance overhead due to the frequent notifications sent to all observers. Real-world example…
Short 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 (…
Short answer: 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 Exa…
Short answer: 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…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The ISortStrategy interface defines a common method (Sort) that all concrete strategies must implement. This allows clients (in this case, the Sorter class) to work with any strategy that implements this interface. public interface ISortStrategy
{ void Sort(List<int> list); }
Discount rules are Strategy objects: PercentageOff, FlatOff, BuyOneGetOne—checkout picks one without a huge if/else.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The State Pattern introduces a separate class for each state, which can lead to an increase in the number of classes in the system. For systems with many states, this can cause complexity.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: When you have an object that can be in multiple predefined states and its behavior depends on the current state (e.g., traffic lights, order processing systems).
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The ITrafficLightState interface defines a method (Change) that allows the traffic light to transition between states (Red, Green, Yellow).
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The ITrafficLightState interface defines a method (Change) that allows the state to transition to another state. The method accepts a TrafficLight object as a parameter to facilitate the state change. public interface ITrafficLightState { void Change(TrafficLight light); } Each concrete state class (Red, Green, Yellow) will implement this interface, defining the specific behavior of the traffic light for that state.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The Singleton can act as a global variable, which may make it harder to track state changes and can lead to issues with dependencies.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 needed. public class Singleton
{
private static readonly Singleton _instance = new Singleton();
private Singleton() { }
public static Singleton Instance => _instance;
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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).
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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, such as configuration settings, logging, or database connections.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 only created once and then reused.
{
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 }
}
}
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: Used to delay the creation or initialization of an expensive object until it is actually needed, like the ProxyImage example above.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The proxy allows you to delay the creation of resource-intensive objects (like loading an image) until it's actually needed, optimizing resource usage.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: The client interacts with the proxy (ProxyImage), which implements the same interface (IImage) as the real subject (RealImage).
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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(); }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: In a role-playing game (RPG), characters or enemies can be cloned from a prototype template (e.g., an "Archer" prototype) and customized with different attributes (e.g., health, attack power) to create new characters or enemies.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 that referenced objects are also cloned, not just referenced.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: This interface defines the Clone() method that concrete prototypes must implement. This method returns a new object that is a copy of the current object. public interface ICloneable
{ ICloneable Clone(); }
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: A news website where multiple users subscribe to receive notifications when new articles or breaking news are published.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: If there are a large number of observers or if the state changes frequently, the Observer Pattern can lead to performance overhead due to the frequent notifications sent to all observers.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short 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).
When order status changes, observers update email, SMS, and analytics without the Order class knowing each one.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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
{ void Subscribe(IObserver observer); void Unsubscribe(IObserver observer); void Notify(string news); }
When order status changes, observers update email, SMS, and analytics without the Order class knowing each one.
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Short answer: 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 the text to its previous state.
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.