EasyPython

Abstract Factory

PythonDesign PatternsCreational

Abstract Factory produces *families* of related objects that must stay
consistent with each other — e.g. all the widgets for one UI theme.

Implement get_factory(theme) returning a LightFactory or DarkFactory
for 'light'/'dark' (raise ValueError otherwise). Each factory has
create_button() and create_checkbox(), both .render()-able.

solve(themes) returns [button.render(), checkbox.render()] for each theme.

solve(['light'])[['light-button', 'light-checkbox']]

Sample tests

Test #1Multiple themes in sequence
Input: [["light","dark","light"]]
Output: [["light-button","light-checkbox"],["dark-button","dark-checkbox"],["light-button","light-checkbox"]]
Test #2Light theme family
Input: [["light"]]
Output: [["light-button","light-checkbox"]]
Test #3Dark theme family
Input: [["dark"]]
Output: [["dark-button","dark-checkbox"]]