Object-Oriented Design, API Design, And Testability
Asked of: Software Engineer
Last updated

What's being tested
These prompts test object-oriented design, API contract design, and testability under changing requirements. Interviewers want to see clear abstractions, explicit invariants, deterministic tests for randomness/concurrency, and complexity-aware implementations.
Patterns & templates
-
Model domain objects first — define
Card,Deck,Move,Game,SnapshotStore; keep state private and expose minimal methods. -
Separate policy from mechanism — inject
RuleSet,Random,Clock,AuthzService, orStorageso behavior changes without rewriting core logic. -
Design APIs around invariants —
draw()should prevent overdraw,snapshot()should return immutable versions,put()should define overwrite/delete semantics. -
Use standard algorithms deliberately — Fisher–Yates
shuffle()isO(n)time,O(1)extra space; avoid biased random swaps or repeated random removal. -
Versioned data structures — snapshotable stores often use per-key sorted version lists;
get(key, snapId)via binary search isO(log v). -
REST robustness checklist — validate input, authenticate, authorize, enforce idempotency keys, handle conflicts with
ETag/version fields, return precise4xx/5xx. -
Test seams — inject deterministic RNGs, fake clocks, in-memory repositories, and mock clients; cover ties, empty decks, duplicate requests, races, and rollback cases.
Common pitfalls
Pitfall: Jumping straight to classes without clarifying operations, mutability, error behavior, and expected scale.
Pitfall: Treating randomness or concurrency as “hard to test” instead of injecting dependencies and asserting deterministic outcomes.
Pitfall: Overengineering with inheritance-heavy hierarchies when a small interface plus composition would be simpler and more extensible.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Design a deck of cards with shuffle/drawApple · Software Engineer · Technical Screen · medium
- Refactor rock–paper–scissors for config and tiesApple · Software Engineer · Onsite · Medium
- Design card deck with shuffle and orderApple · Software Engineer · Onsite · Medium
- Implement deep clone for complex objectsApple · Software Engineer · Technical Screen · Medium
- Design a snapshotable key-value storeApple · Software Engineer · Technical Screen · Medium
- Implement a robust REST API methodApple · Software Engineer · Technical Screen · hard
Related concepts
- Stateful Data Structures And OOP API DesignCoding & Algorithms
- Scalable Backend Architecture And Data ModelingSystem Design
- API Integration And External Service DesignSystem Design
- Object-Oriented Design And Concurrency-Safe LLDSoftware Engineering Fundamentals
- Debugging, Observability, And Production OperationsSoftware Engineering Fundamentals
- Core Data Structures, Sorting, And ComplexityCoding & Algorithms