Exercise 1: Adding a Slider to the Abstract Factory Family — Possible Solution ==================================================================== THE NEW ABSTRACT PRODUCT AND CONCRETE PRODUCTS ------------------------------ class Slider(ABC): @abstractmethod def render(self): pass class LightSlider(Slider): def render(self): return 'Light slider' class DarkSlider(Slider): def render(self): return 'Dark slider' EXTENDING THE ABSTRACT FACTORY AND BOTH CONCRETE FACTORIES ------------------------------ class UIFactory(ABC): @abstractmethod def create_button(self): pass @abstractmethod def create_checkbox(self): pass @abstractmethod def create_slider(self): pass # new class LightThemeFactory(UIFactory): def create_button(self): return LightButton() def create_checkbox(self): return LightCheckbox() def create_slider(self): return LightSlider() # new class DarkThemeFactory(UIFactory): def create_button(self): return DarkButton() def create_checkbox(self): return DarkCheckbox() def create_slider(self): return DarkSlider() # new VERIFYING CONSISTENT FAMILIES ------------------------------ Building all three components through each factory: LightThemeFactory -> Light button | Light checkbox | Light slider DarkThemeFactory -> Dark button | Dark checkbox | Dark slider Every component produced through a given factory call belongs to the same family - exactly as this chapter's own two-product example demonstrated, now confirmed with a third product added. WHY EXTENDING THE ABSTRACT FACTORY (RATHER THAN ONLY THE CONCRETE ONES) MATTERS ------------------------------ Adding create_slider() as an abstract method on UIFactory itself, rather than only adding it directly to LightThemeFactory and DarkThemeFactory, ensures any future third theme factory would be required to implement it too - the abstract base class is what enforces that every family stays complete and consistent, not just a convention followed by the two factories that happen to exist today. WHY THIS WORKS AS AN ANSWER ------------------------------ The new classes follow this chapter's own existing Button/Checkbox pattern exactly, the abstract method is added to the base UIFactory class (not just the concrete subclasses) to preserve the enforcement guarantee, and the result is verified by actually building and rendering all three components through both factories rather than assuming the extension would work.