Exercício prático · SOLID & Design Patterns

Practice lab: Separate a business rule from a provider

do caderno de estudos · atualizado em 2 de outubro de 2026
Para quem vai encarar entrevista de SOLID & Design Patterns2 min

Tente resolver a tarefa antes de consultar os critérios. Compare o resultado e explique o que mudou no seu raciocínio.

Tarefa e critérios de verificação

Task, 15 minutes: a checkout service calculates a shipping quote by calling one carrier's SDK directly. Introduce the smallest boundary that lets the same checkout use a second carrier and a deterministic fake in a test.

Check your work:

  • Checkout depends on a quote contract with explicit inputs, currency, amount, and failure behavior. Carrier-specific request/response mapping stays in the adapter.
  • The same contract checks run against both adapters. Neither silently changes units, returns a negative price, or converts failure into a free quote.
  • A fake quote provider lets the business-rule test run without a network call.

Follow-up: explain which change would still require editing checkout and why an abstraction does not make every future change free. Avoid adding factories or inheritance unless this example needs them.

No app, a tarefa fica visível e você pode revelar os critérios depois da tentativa. Use as notas para registrar sua solução.

Praticar este exercício no app