Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
ProgrammingMiddleOccasionalScenario

How would you approach object composition when operations can fail or time out?

Answer

Start by making inputs, outputs, ownership and failure behavior explicit before choosing an implementation. Focus on object composition when operations can fail or time out. Use small deterministic units plus integration behavior at real boundaries as the oracle. Cover normal flow, invalid inputs, exceptions, concurrency and resource cleanup. Keep data and dependencies controlled enough to reproduce failures. Release only when tests fail for one understandable reason and the code remains easy to change.

Strong answer includes

  • explicit risk and test oracle for object composition
  • controls side effects and dependencies
  • designs for deterministic tests
  • measurable evidence and residual-risk statement

Practical example

An Order object composed of a Payment sub-object and a Shipment sub-object left Shipment half-initialized when the Payment step timed out mid-construction, and later code assumed Shipment was always valid and threw a null pointer error. The approach was to make composition explicit and staged, only exposing the composed Order once every sub-object had confirmed success or the whole construction failed atomically.

#programming#test-code#object-composition

Sources

Git referenceGit Project · Version control concepts and commandsPlaywright best practicesMicrosoft · Reliable modern browser automationMDN JavaScript GuideMozilla · Functions, closures, objects, classes, error handling and asynchronous programming (promises, async/await)