Component templates and instance overrides
I was asked this
No reports yet. Sign in to say where you were asked it.
An object-oriented design interview question asked in Figma's coding round, last asked Oct 2021. It tests object-oriented design, data modeling and versioning.
A template defines a reusable component, such as a button with a label, a color and a corner radius. Users create instances of it and override some fields, for example the label text. The author can publish later revisions, and earlier revisions stay available to the instances that use them. Design a compact JSON-like representation and the in-process classes for this lifecycle.
An instance must store only what its owner changed, never copies of the defaults. When a new revision is out, the owner can preview it and apply it. Compatible overrides survive. An override of a field that was removed, or whose type changed, is reported as a conflict, and nothing is committed until every conflict is resolved.
Requirements
- Functional: publish a revision of a template; create an instance from a revision; set and clear overrides; read an instance's effective value for any field (the override if there is one, else the revision's default); preview an update to a newer revision; apply it, or refuse it while conflicts remain.
- Non-functional: overrides take space proportional to what the user changed. Calls are synchronous and run in one process. Storage engines, network APIs, rendering and real-time collaboration are out of scope.
Clarifying questions
- Can components nest, so an instance contains other instances whose fields can also be overridden?
- Do fields have stable IDs that survive a rename, or are they addressed by name?
- What field types exist (text, color, number, enum), and which type changes are compatible, if any?
- If the author changes a default that the user had overridden, does the override still win?
- Can an instance skip revisions, going from revision 1 straight to revision 4?
What a strong answer covers
- The representation: a template revision as a schema of fields with ID, type and default; an instance as
{template_id, revision, overrides: {field_id: value}}, with nested paths for nested components. - Classes with one job each, for example
Template,Revision,Instance,OverrideSetandUpdatePlan, and where effective values are resolved. - The update preview as a plan with three lists: fields that change through inheritance, overrides kept, and conflicts (field removed, type changed) with the old value.
- Applying a plan atomically: the instance changes only when the plan has no unresolved conflicts, otherwise it stays exactly as it was.
- Why stable field IDs matter for renames and reordering.
- Tests: an untouched instance follows the new defaults, a kept override, a removed field, a type change, and an apply that is refused.
Follow-ups
- How do you resolve a conflict: drop the override, convert it, or map it to a new field?
- Nested instances: how do overrides on an inner component survive when the outer template changes?
- How would you serialize the representation so an older client can still read a newer revision?
Where it's asked
- Figma · Coding · Last asked Oct 202160 min · One or two pair-programming rounds against provided tests
What it tests
object-oriented design · data modeling · versioning
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
