
;; Abstract factory folds into a map of constructor functions:
;; the client knows the keys, not the family behind them
;; Concrete factory 1
(def factory-1
{:create-a (fn [] #(println "test A1"))
:create-b (fn [] #(println "test B1"))})
;; Concrete factory 2
(def factory-2
{:create-a (fn [] #(println "test A2"))
:create-b (fn [] #(println "test B2"))})
;; Client — works with any factory that offers both keys
(defn check-factory [factory]
(let [product-a ((:create-a factory))
product-b ((:create-b factory))]
(product-a)
(product-b)))
(check-factory factory-1)
;; printed: test A1
;; test B1
(check-factory factory-2)
;; printed: test A2
;; test B2