替换原则

泛型

;; 没有可供替代的基类:向量什么都能装,
;; 让这些值可以互换的是共同的协议
(defprotocol Vehicle
  (test-it [this]))

(defrecord Car [] Vehicle (test-it [_] (println "test Car")))
(defrecord Truck [] Vehicle (test-it [_] (println "test Truck")))

(def items [(->Car) (->Truck)])

(doseq [item items] (test-it item))

;; “是……的一种”也可以直接声明在普通关键字上
(derive ::car ::vehicle)
(println "car is a vehicle:" (isa? ::car ::vehicle))