«interface»
GUIFactory
+ makeButton()
+ makeCheckbox()
WinFactory
MacFactory
«interface»
Button
«interface»
Checkbox
One factory, a whole family
1interface GUIFactory {2 Button makeButton(); // one method per product3 Checkbox makeCheckbox(); // in the family4}5class WinFactory implements GUIFactory { ... } // all-Windows6class MacFactory implements GUIFactory { ... } // all-Mac78GUIFactory f = onMac ? new MacFactory() : new WinFactory();9Button b = f.makeButton();10Checkbox k = f.makeCheckbox(); // guaranteed to match b
State
factoryone method per product