Exercise 1: Adding get_item_count() to the Stateless Service — Possible Solution ==================================================================== THE NEW METHOD ------------------------------ class StatelessCartService: # ...existing add_item()/get_cart() unchanged... def get_item_count(self, current_cart): return len(current_cart) Follows this chapter's own StatelessCartService shape exactly - it takes current_cart as an argument, just like get_cart() and add_item(), and holds no state of its own between calls. VERIFYING IT WORKS AFTER A SIMULATED RESTART ------------------------------ cart after two adds: ['Widget', 'Gadget'] item count from a fresh service instance, given only client-supplied cart data: 2 Two items were added via the existing add_item() method, producing a cart the CLIENT holds onto. A brand-new StatelessCartService instance - simulating this chapter's own server-restart scenario - correctly reports a count of 2, using only the cart data supplied by the client in the call itself. WHY THIS CONFIRMS THE PATTERN GENERALIZES TO NEW METHODS ------------------------------ This chapter's own get_cart() already survived a simulated restart. This exercise confirms a BRAND NEW method, added after the fact, automatically inherits the same property - not because get_item_count() does anything special, but because nothing about StatelessCartService's own design depends on server memory in the first place. Any method written the same way (taking the relevant state as a parameter, rather than reading it from self) gets restart-survival for free. WHY THIS WORKS AS AN ANSWER ------------------------------ The new method follows this chapter's own established stateless shape exactly, and it's verified working correctly against a genuinely fresh service instance - the same restart-simulation technique this chapter used for get_cart() - rather than only assumed to inherit the property.