Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
The Shape class is the abstraction. It holds a reference to the IDrawingAPI and delegates the drawing task to it. It defines the common interface Draw() that all shapes must implement. public abstract class Shape { prote…
Answer: The Adapter pattern allows you to integrate existing systems or third-party libraries without modifying their code. It enables compatibility between incompatible interfaces. What interviewers expect A clear defin…
Answer: The ITarget interface defines the expected interface that the client will use. It has a method Request() that the client expects to call. public interface ITarget { void Request(); } What interviewers expect A cl…
The IUIFactory interface defines methods for creating abstract product types like buttons and checkboxes. This ensures that every concrete factory will implement the same methods, but each will provide platform-specific…
Answer: the existing classes. This pattern allows you to keep your object classes stable and add functionality through new visitor classes. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four…
chieved by selecting different algorithms. 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 w…
Answer: lgorithm. These algorithms can be tested, optimized, or replaced without ffecting the context or the other algorithms. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns pro…
Answer: pplication log to the same destination (e.g., a log file or a central logging service). What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance,…
ctual state (the text) and provides methods to change the state, save the current state to a Memento, and restore a previous state from a Memento. The Save() method creates a new TextMemento capturing the current state o…
Answer: dding new features like message filtering or logging can be done in the mediator without affecting the users. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Tra…
ccess the elements sequentially, leading to cleaner and more maintainable code. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability,…
n iterator for that collection. 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 us…
ccess to the shared flyweight objects. 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…
Answer: synchronous, allowing components (like the DVD player) to load or process content in the background, improving user experience. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Pat…
mplifier or DVDPlayer, reducing tight coupling between them. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) Wh…
Answer: n individual object, while a group of shapes can be treated as a composite object. The Composite Pattern makes it easier to manage complex graphical objects that contain simple shapes. What interviewers expect A…
ny child components but implements the ShowInfo() method to display its name. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, s…
ctions without needing to track individual changes manually. What interviewers expect A clear definition tied to GoF Patterns in Gang of Four Patterns projects Trade-offs (performance, maintainability, security, cost) Wh…
Answer: The pattern introduces additional classes (visitors), which can make the system more complex, especially when the number of elements and visitors increases. What interviewers expect A clear definition tied to GoF…
Answer: You can add new operations (like taxes or shipping costs) by simply creating new visitor classes without needing to modify the existing elements (Book, Fruit). This makes it easier to extend functionality in the…
Answer: The visitor interface defines a visit method for each type of element. Each Visit method encapsulates the operation to be performed on the corresponding element. What interviewers expect A clear definition tied t…
The IShoppingCartElement interface declares the Accept method, which allows the element to accept a visitor. Each element (like Book, Fruit) will implement this interface to allow a visitor to operate on it. public inter…
If the template method involves a large number of steps, or if there are many subclasses with different variations of steps, the code can become harder to manage and maintain. Conclusion: The Template Method Pattern is a…
Answer: If you are creating a framework where clients need to customize only certain steps of a predefined process, the Template Method Pattern allows them to override the necessary methods while ensuring the common work…
The PastaRecipe class is a concrete subclass that implements the specific details of the steps defined in the abstract Recipe class. The steps like gathering ingredients, preparing, and cooking are all tailored to pasta.…
Gang of Four Patterns Design Patterns in C# · GoF Patterns
IDrawingAPI and delegates the drawing task to it. It defines the common
interface Draw() that all shapes must implement.
public abstract class Shape
{
protected IDrawingAPI _drawingAPI;
protected Shape(IDrawingAPI drawingAPI) => _drawingAPI =
drawingAPI;
public abstract void Draw();
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: The Adapter pattern allows you to integrate existing systems or third-party libraries without modifying their code. It enables compatibility between incompatible interfaces.
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 ITarget interface defines the expected interface that the client will use. It has a method Request() that the client expects to call. public interface ITarget { void Request(); }
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
types like buttons and checkboxes. This ensures that every concrete factory
will implement the same methods, but each will provide platform-specific
products.
public interface IUIFactory
{
IButton CreateButton();
ICheckbox CreateCheckbox();
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: the existing classes. This pattern allows you to keep your object classes stable and add functionality through new visitor classes.
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
chieved by selecting different algorithms.
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: lgorithm. These algorithms can be tested, optimized, or replaced without ffecting the context or the other algorithms.
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: pplication log to the same destination (e.g., a log file or a central logging service).
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
ctual state (the text) and provides methods to change the state, save the current
state to a Memento, and restore a previous state from a Memento.
editor.
public class TextEditor
{
private string _text;
public void Write(string text) => _text = text;
public TextMemento Save() => new TextMemento(_text);
public void Restore(TextMemento memento) => _text =
memento.Text;
public override string ToString() => _text;
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: dding new features like message filtering or logging can be done in the mediator without affecting the users.
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
ccess the elements sequentially, leading to cleaner and more maintainable code.
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
n iterator for that collection.
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
ccess to the shared flyweight objects.
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: synchronous, allowing components (like the DVD player) to load or process content in the background, improving user experience.
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
mplifier or DVDPlayer, reducing tight coupling between them.
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: n individual object, while a group of shapes can be treated as a composite object. The Composite Pattern makes it easier to manage complex graphical objects that contain simple shapes.
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
ny child components but implements the ShowInfo() method to display its name.
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
ctions without needing to track individual changes manually.
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 pattern introduces additional classes (visitors), which can make the system more complex, especially when the number of elements and visitors increases.
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: You can add new operations (like taxes or shipping costs) by simply creating new visitor classes without needing to modify the existing elements (Book, Fruit). This makes it easier to extend functionality in the future.
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 visitor interface defines a visit method for each type of element. Each Visit method encapsulates the operation to be performed on the corresponding element.
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 element to accept a visitor. Each element (like Book, Fruit) will implement this
interface to allow a visitor to operate on it.
public interface IShoppingCartElement
{
void Accept(IShoppingCartVisitor visitor);
}Gang of Four Patterns Design Patterns in C# · GoF Patterns
subclasses with different variations of steps, the code can become harder to
manage and maintain.
Conclusion:
The Template Method Pattern is a powerful way to define the structure of an algorithm
while allowing subclasses to customize specific steps. It's ideal when you want to reuse a
Follow:
common workflow while providing flexibility to modify particular steps. It is frequently used in
frameworks and libraries, where the overall process must remain consistent, but certain
aspects can be customized or extended. This pattern ensures that the general algorithm
remains the same while giving subclasses the freedom to tailor specific steps to their needs.
Visitor Pattern: Adding New Operations Without Modifying Object
Structures
Definition:
The Visitor Pattern separates an algorithm from the object structure on which it operates. It
allows you to add new operations to existing object structures without modifying the
structures themselves. Instead of embedding operations directly into the objects, you define
a visitor that knows how to operate on each type of object in the structure.
Use Case:
A typical use case for the Visitor Pattern is calculating taxes or discounts for different
product types in a shopping cart. Each product type (e.g., books, fruits, electronics) might
require different calculations, and the Visitor Pattern allows you to easily add new types of
operations (e.g., tax calculation, discount application) without altering the objects in the
shopping cart.
Code Breakdown:
Gang of Four Patterns Design Patterns in C# · GoF Patterns
Answer: If you are creating a framework where clients need to customize only certain steps of a predefined process, the Template Method Pattern allows them to override the necessary methods while ensuring the common workflow remains intact.
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
of the steps defined in the abstract Recipe class. The steps like gathering
ingredients, preparing, and cooking are all tailored to pasta.
public class PastaRecipe : Recipe
{
protected override void GatherIngredients()
{
Console.WriteLine("Gathering pasta, sauce, and cheese.");
}
protected override void Prepare()
{
Console.WriteLine("Boiling pasta and preparing sauce.");
}
protected override void CookMethod()
{
Console.WriteLine("Cooking pasta with sauce.");
}
}