I'm trying to extend library DomKM/silk.
Specifically there's deftype Route which implements protocol Pattern, which has method implementations, which I'd like to reuse in my custom implementation of Pattern protocol.
https://github.com/DomKM/silk/blob/master/src/domkm/silk.cljx#L355
(deftype Route [name pattern] Pattern (-match [this -url] (when-let [params (match pattern (url -url))] (assoc params ::name name ::pattern pattern))) (-unmatch [this params] (->> (dissoc params ::name ::pattern) (unmatch pattern) url)) (-match-validator [_] map?) (-unmatch-validators [_] {})) Ok so my implementation would look somehow like this, but I'd like to "inherit" Route's methods. I mean execute some custom logic first and then pass it to original Route methods.
(deftype MyRoute [name pattern] silk/Pattern (-match [this -url] true) ;match logic here (-unmatch [this {nm ::name :as params}] true) ;unmatch logic here (-match-validator [_] map?) (-unmatch-validators [_] {})) How is this done in clojure / clojurescript?
Routeobject and letMyRoute's methods delegate to theRoute's. Objects created bydeftypeare Java classes, so you might be able do what you want by using one of the two Java interop macros that allow inheritance:proxyandgen-class.gen-classis probably overkill, so if you take this path, I suggestproxy. However, this goes against the design goals of Clojure, so you might want to simply reimplement the code you need.Routeare not large. If you want to do this a lot, you could write functions outside of thedeftypeobjects and call them usingPatternmethods.(proxy [Route] [name pattern] (-match []))I get an errorjava.lang.VerifyError: Cannot inherit from final class. Is it even possible to use proxy on deftype?