Паттерны / Структурные паттерны
image

(require '[clojure.string :as str])

;; Clojure has no inheritance; the nearest thing to "adapter is-a adaptee"
;; is teaching the adaptee's own type the target protocol, with no wrapper

;; Target
(defprotocol IText
  (get-text [this]))   ; Request()

;; Adapter — the adaptee type itself gains Request()
(extend-type clojure.lang.PersistentVector
  IText
  (get-text [rows] (str/join "\n" rows)))   ; delegates to SpecificRequest()

;; Client — an ordinary vector now answers the target protocol
(def rows ["line 1" "line 2"])
(println (get-text rows))
;; line 1
;; line 2


Преобразует интерфейс класса в другой интерфейс, ожидаемый клиентами. Обеспечивает совместную работу классов, которая была бы невозможна без данного паттерна из-за несовместимости интерфейсов.