Daily iOS
CS fundamentals and algorithms

Inventory domain design

You're designing a Swift inventory system that processes receive, reserve, sell, and cancel operations in sequence. What domain type protects the invariants on stock quantities?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

One Inventory value type per product holds onHand and reserved, accepts every operation only through mutating methods that check reserved <= onHand and reject negatives inside, and uses private(set) so nothing outside can change the quantity fields directly.

Share a question