Last active
November 14, 2018 00:39
-
-
Save fiddlerwoaroof/33f7c87294c6da2c176fe14dccd3b39e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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