SOLID & Design Patterns Interview Question #115

What is the Result Pattern?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

The Result Pattern represents an operation's success or expected failure explicitly instead of using exceptions for every business outcome. A result can contain a value on success and structured errors on failure.

Detailed Explanation

The Result Pattern represents an operation's success or expected failure explicitly instead of using exceptions for every business outcome. A result can contain a value on success and structured errors on failure.

It is useful for validation and business-rule failures that callers are expected to handle. Exceptions remain appropriate for unexpected or exceptional failures.

Code Example

public record Result<T>(
    bool IsSuccess,
    T? Value,
    string? Error);

return customer is null
    ? new Result<Customer>(false, null, "Not found")
    : new Result<Customer>(true, customer, null);