Mock Interview: Creational
Mock interview: creational simulates a 45-minute senior loop on object-creation patterns.
Introduction
Mock interview: creational simulates a 45-minute senior loop on object-creation patterns. Each question includes junior, mid, and senior answers so you see the upgrade path explicitly.
The story
Candidate asked "implement Singleton" — wrote double-checked locking from memory. Follow-up: "How test code depending on it?" Froze. Singleton answer correct; test answer revealed gap. Mock practice fixes this.
The business problem
Creational questions trap candidates who memorize implementation but miss judgment:
- Singleton testability: can't mock global instance.
- Factory overuse: Abstract Factory for one product.
- Builder vs constructor: when telescoping actually matters.
- DI vs Singleton: modern alternative not mentioned.
The problem teams faced
Creational mock covers:
- Singleton — when, testability, DI alternative.
- Factory Method vs Abstract Factory — force distinction.
- Builder — complex object with optional fields.
- Prototype — clone vs reconstruct; when copy expensive.
Understanding the topic
Intent: Practice creational Q&A at three seniority levels.
- Junior — definition + naive implementation.
- Mid — force + basic trade-off.
- Senior — alternatives, testing, production story, when-not.
Internal architecture
Mock Q1: Singleton — three answers:
JUNIOR: "One instance." + writes double-checked locking.MID: "Global state; hurts testing. Use DI scoped singleton."SENIOR: "Creational — one instance per process. Force: expensive sharedresource. Trade-off: hidden dependency, test difficulty. Alternative: DIcontainer singleton scope. Story: metrics registry — legacy boundary requiredhand-roll. Test: inject MetricsCollector interface; prod uses singleton impl,tests use fake. Never for request-scoped data."
Visual explanation
Three diagrams cover answer levels, Factory vs Abstract Factory, Singleton test seam:
Informative example
Mock Q2: Builder — senior answer sketch:
// Force: Order with 12 optional fields — constructor telescoping// Senior: "Builder when >4 optional params or validation between steps.// Alternative: factory function with defaults object in TS.// Story: checkout OrderBuilder — validate address before payment step.// Not Builder for 3-field DTO — YAGNI."class OrderBuilder {private order: Partial<Order> = {}withItems(items: LineItem[]) { this.order.items = items; return this }withShipping(addr: Address) { /* validate */ this.order.shipTo = addr; return this }build(): Order { /* final validation */ return Order.create(this.order) }}
Execution workflow
Timer 45 min
4-5 questions.
Real-world use
Senior loops at Google/Meta often start creational then pivot to system design; Stripe interviews Factory/Adapter for payment provider integration.
Production case study
Singleton freeze on test question:
- Implementation: correct double-checked locking.
- Follow-up: "How test dependents?" — no answer.
- Lesson: always pair creational with test seam.
Trade-offs
- Pro: explicit junior/mid/senior ladder accelerates learning.
- Con: mock ≠ real interviewer unpredictability.
Decision framework
- Every creational answer: force, test, when-not.
- Factory Method: one product type varies. Abstract Factory: product families.
- Builder: many optional fields + step validation.
Best practices
- Never write Singleton code without mentioning test alternative.
- Prototype: mention structuredClone vs custom clone when fields are complex.
- Object Pool: only when allocation measurably expensive.
Anti-patterns to avoid
- Abstract Factory with one family — deletion candidate.
- Singleton for database connection in serverless — wrong scope.
Common mistakes
- Confusing Factory Method (method) with Simple Factory (function).
- Builder for 2-field object — overengineering.
Debugging tips
- If stuck on Factory vs Abstract Factory — ask "one product or family?"
Optimization strategies
- Prepare 4 creational stories: Singleton removal, Factory for payments, Builder for orders, Prototype for templates.
Common misconceptions
- Simple Factory is not GoF Factory Method — know the distinction.
- DI replaces most Singleton hand-rolls — say it in interview.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionFactory Method vs Abstract Factory?+
Answer
Follow-up
2AdvancedQuestionTest Singleton dependents?+
Answer
Follow-up
3IntermediateQuestionBuilder vs factory function?+
Answer
Follow-up
Summary
You can upgrade creational answers from junior to senior and survive the Singleton test follow-up. Complete this mock aloud — you own Creational Interview prep.