Handler Interface (Logger):?
Short answer: The Logger class is the handler interface that defines the contract for handling log messages. It includes a reference to the next logger in the chain (NextLogger) and a method (LogMessage) to process a message. If the current handler cannot handle the message, it passes the request along to the next handler in the chain. public abstract class Logger
Example code
{ protected Logger NextLogger; public void SetNext(Logger nextLogger) => NextLogger = nextLogger; public void LogMessage(string message, LogLevel level)
{
if (CanHandle(level))
{ Handle(message); } else { NextLogger?.LogMessage(message, level); }
} protected abstract bool CanHandle(LogLevel level); protected abstract void Handle(string message); }
Real-world example (ShopNest)
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png