← Stackadapt Interview Insights
The 'collect all errors, don't stop at the first one' part is what tripped me up initially.
Start by writing a simple validation function for each class that iterates over all fields and accumulates errors into a list, avoiding early returns. Then refactor by extracting common validation rules into reusable functions or a shared validator class, and show how each class can compose these rules while still handling class-specific logic.
Pro tip: Mention that you'd use a validation library or pattern like Specification or Strategy to make rules composable and testable, but keep the initial implementation simple to demonstrate core logic. Also, discuss how you'd handle cross-field validations and error message localization as a natural extension.
Ask about the domain classes, validation rules, and expected error format. Confirm that all errors should be collected and that shared code is desired.
For each class, write a function that checks each field against its rules, appends errors to a list, and returns the list without short-circuiting.
Extract shared rules (e.g., non-empty, length, format) into standalone functions or a validator object that can be reused across classes.
Propose a composition-based approach: each class defines its fields and associated rules, and a generic validator applies them. Discuss trade-offs between inheritance and composition.
Explain how new rules can be added without modifying existing code, and how unit tests can cover both shared and class-specific validations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.