skip to content

In a B2B web console, an order-summary panel reused on checkout review, the order page and account history has grown eleven per-screen flags; what went wrong, and what would you change?

level: seniorimportance: should knowfreq 42%

answer

  1. locally cheapest change, globally costly
  2. flags named after callers
  3. render core versus screen actions
  4. map each source to one view model
  5. sometimes duplicate instead

basics

~20 s

The shared panel learned about its callers: teams added flags instead of composing, leaving untested combinations and no owner. Keep a core that renders lines and totals, and let each screen compose its own data mapping and actions.

solid answer

~50 s

I'd diagnose first: flags like `isHistory` and `showReorderButton` mean screen logic lives inside a shared part, eleven booleans allow 2,048 combinations of which only three are used, and every change needs three teams. Then I'd find the seam. What is identical everywhere is rendering line items, totals and currency, so that becomes a core that takes a small view model and only renders. What differs is the data source (a draft, a live order, a snapshot) and the actions (edit, cancel, reorder), so each screen gets its own wrapper, owned by its team, that maps its source and places its actions. Migrate one screen at a time and delete flags as callers leave. If checkout review grows into an editor with promo codes, I'd stop sharing beyond the core: a duplicated layout is cheaper than an abstraction serving an editor and two read-only views.

code

pseudocode · 10 lines
pseudocode
// before: one switchboard
OrderSummaryPanel(orderId, isHistory, showEditLinks, showReorderButton,
                  showCancelButton, hideTax, compact, showPromoField, ...)

// after: one render core, one composition per screen
OrderSummaryCore(lines, totals, currency, density)

CheckoutReviewSummary(draft)  -> Core(fromDraft(draft))   + EditLinks + PromoField
OrderPageSummary(order)       -> Core(fromOrder(order))   + CancelButton + InvoiceLink
HistorySummary(snapshot)      -> Core(fromSnapshot(snap)) + ReorderButton

go deeper

for a junior

Recall the warning sign: a shared component whose properties are named after the screens that use it, so changing it for one screen can break another.

for a middle

Explain how to separate the parts that render identically everywhere from the parts that differ per screen, and how each screen maps its data into one small view model.

for a senior

Diagnose the coupling and ownership problem, propose an incremental migration, and say when duplication beats sharing, such as checkout review turning into an editor.

for a principal

Set the convention for feature teams: who owns a shared feature component, where screen-specific needs go, and how review stops caller-named properties before they reach eleven.

## The symptom A B2B web admin console shows an **order-summary panel** — line items, totals, tax, currency — on three screens owned by different teams: **checkout review**, the **order page**, and the account's **order history**. Each time a team needed something different, it added a boolean property: `showEditLinks`, `showReorderButton`, `showCancelButton`, `hideTax`, `compact`, `isHistory`, `showPromoField`, `readOnlyQuantities`, and so on, until there are eleven. Then a fix for checkout review broke the history screen, and nobody owned the regression. ## Why flags accrete Adding one more flag is always the locally cheapest change: one property, one `if`, no new file. The costs arrive later and land on someone else: - **Combinations explode.** Eleven booleans allow 2,048 combinations; three screens use three of them, and nobody tests the rest. - **The shared component learns about its callers.** A flag named `isHistory` means screen logic now lives inside the shared part. - **Ownership blurs.** Every team edits the panel, so no team owns it, and every change needs three teams' review. - **Data shapes leak in.** Checkout review shows a *draft* with no order ID yet; history shows a *snapshot* of prices at the time; the order page shows the live order. The panel ends up handling all three shapes. ## Find the real seam | Concern | Checkout review | Order page | History | Shared? | |---|---|---|---|---| | Line items, totals, currency formatting | same | same | same | yes | | Source of the data | draft cart | live order | snapshot | no | | Actions | edit, apply promo | cancel, download invoice | reorder | no | | Editable quantities | yes | no | no | no | What is truly shared is **rendering a summary**: lines, totals, formatting. What differs is **where the data comes from and what the user can do** — exactly the things the flags were switching. ## The refactor 1. Extract a **shared summary core** that accepts a small view model (lines, totals, currency) and only renders it. It knows nothing about drafts, orders or snapshots. 2. Give each screen its **own composition**: a checkout-review summary, an order-page summary and a history summary, each owned by the screen's team. Each one maps its source into the view model and places its own actions around the core — the composition mechanism (passing children or regions into a component) is a framework matter; the decision is that actions belong to the screen. 3. Move one screen at a time onto core plus wrapper, and delete each flag when its last caller leaves. 4. Give the core one owning team, and require that a screen-specific need goes into that screen's wrapper, not into the core. ## Ownership after the refactor - **The core** has one owning team (often the team closest to orders, or the shared-kernel owners). Changes to it are rare and reviewed as changes to a shared contract. - **Each wrapper** belongs to its screen's team, which can change actions, copy and layout without asking anyone. - **The view model** is the contract between them: a handful of typed, documented fields, grown by adding fields rather than by changing existing ones. - **Tests follow ownership:** the core is tested against view models; each wrapper is tested on its own screen with its own data source. ## When to stop sharing Sometimes the right move is **less sharing**. If checkout review needs editable quantities, promo codes and live recalculation, it is a different component that happens to look similar: - duplicating twenty lines of layout is cheaper than one abstraction that must serve an editor and two read-only views; - the editor changes on checkout's schedule, the read-only views on everyone else's; - share the formatting and the line-item row, and let checkout own its editor outright. ## Flags are not the enemy A component with two or three properties describing **variations of itself** — dense versus comfortable spacing, with or without a header — is healthy. The smell is properties named after screens, properties that only make sense in combination, and a count that grows with every new caller. Replacing eleven booleans with a single `screen` enumeration keeps the problem: the shared part still switches on who is calling it. ## What to say in the round Diagnose before prescribing: name the coupling, the untested combinations and the blurred ownership. Then show the seam table, the extraction plan and the rule that keeps it from coming back — and say when you would duplicate instead.

  • Aren't a few flags perfectly fine?
    Yes. A property describing a variation of the component itself, such as density or whether a header shows, is healthy. The warning signs are properties named after screens, properties that only work in particular combinations, and a count that grows with every new caller.
  • Why not let the shared panel fetch the order by ID so each screen just passes the ID?
    Because the three screens do not share a source. Checkout review shows a draft with no order ID yet, and history must show prices as they were, not as they are. Fetching inside the core would force it to know all three sources. Each screen maps its own data into the view model instead.
  • How do you migrate without a risky big-bang change?
    Extract the core next to the existing panel, move one screen onto core plus wrapper behind its own tests, and delete each flag when its last caller leaves. The panel shrinks screen by screen until it can be removed, and each step ships on its own.

  • Adding one more boolean flag is the right default for each new screen.
  • Any duplication between two screens must be removed by sharing a component.
  • Replacing eleven flags with a single screen enumeration fixes the coupling.
  • The shared panel should fetch the order itself so callers only pass an ID.
  • A shared feature component can be edited by every team without one owner.