← StackAdapt Interview Insights
First, clarify the domain classes and validation rules, then implement each validator to accumulate errors in a collection rather than throwing on the first failure. After implementing, discuss how to extract shared validation logic into a common utility or base class, considering trade-offs like coupling and reusability.
Pro tip: Mention that returning a list of errors is often better for API responses because clients can display all issues at once, improving user experience. Also, discuss how to structure error objects with field names and messages for easy consumption.
Ask about the domain classes, validation rules, and expected error format. Confirm that all errors should be collected and returned, not thrown.
For each class, write a function that iterates over fields, applies validation rules, and appends errors to a list. Ensure no early returns on first error.
Compare the two validators to find shared logic, such as required field checks, string length, or numeric ranges.
Suggest extracting common validations into helper functions or a base validator class. Discuss trade-offs: inheritance vs composition, and how to keep validators flexible.
Explain how the shared approach can be extended for new rules and how to unit test both validators and shared components.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.