Exercise 2: A Worker Implementing Neither Interface — Possible Solution ==================================================================== THE NEW CLASS ------------------------------ class VendingMachineWorker: # implements neither Workable nor Eatable def dispense_snack(self): return "Snack dispensed" Deliberately implements NEITHER of this chapter's own two segregated interfaces - it's not a subclass of Workable or Eatable at all, just an unrelated object that happens to be in the same list. RESULTS ------------------------------ lunch_break_fixed result: ['Human eating lunch'] VendingMachineWorker excluded from lunch: True shift_schedule result: ['Human working', 'Robot working'] VendingMachineWorker excluded from shift schedule: True Running lunch_break_fixed() (filtering by isinstance(w, Eatable)) against a list containing the vending machine correctly returns only the human's own result - the vending machine is silently and correctly excluded, with no crash. A new shift_schedule() function, filtering by isinstance(w, Workable) instead, correctly includes both the human and the robot (both genuinely Workable) while also correctly excluding the vending machine. WHY THIS CONFIRMS THE SEGREGATED-INTERFACE FIX GENERALIZES ------------------------------ This chapter's own original fix only tested excluding a RobotWorker (something that implements ONE of the two interfaces) from an Eatable-only function. This exercise confirms the same isinstance-based filtering correctly excludes something implementing NEITHER interface from BOTH functions - without either function needing any special-case code to handle "an object that isn't even a kind of worker at all." The filtering mechanism doesn't need to know in advance what kinds of non-matching objects might show up; it only needs to check for the one specific capability each function actually requires. WHY THIS WORKS AS AN ANSWER ------------------------------ A genuinely unrelated class (not implementing either interface) is added to the mix, both existing this chapter's own filtering functions are tested against it directly, and both are verified to correctly and silently exclude it rather than crashing or requiring new logic.