Skip to content

Instantly share code, notes, and snippets.

@fiddlerwoaroof
Last active November 14, 2018 00:39
Show Gist options
  • Save fiddlerwoaroof/33f7c87294c6da2c176fe14dccd3b39e to your computer and use it in GitHub Desktop.
Save fiddlerwoaroof/33f7c87294c6da2c176fe14dccd3b39e to your computer and use it in GitHub Desktop.
(ns oop-with-inheritance)
(defn start [arg]
(println "starting: " arg))
(defn stop [sys]
(println "stopping:" sys))
(defn server-system-local [& args]
(apply println "making server system:" args)
{:hello "world!"})
(defn make-system []
(let [state (atom nil)]
(fn [msg & args]
(case msg
:start (reset! state (start (apply server-system-local args)))
:stop (do (stop @state)
(reset! state nil))))))
(defn make-derived-system []
(let [subclass-state (atom {:count 0})
parent (make-system)]
(fn [msg & args]
(case msg
:inc (:count (swap! subclass-state update-in [:count] inc))
:dec (:count (swap! subclass-state update-in [:count] dec))
:stop (do (println "stopping derived system")
(parent :stop))
(apply parent msg args)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment