Created
June 12, 2010 15:35
-
-
Save david-mcneil/435822 to your computer and use it in GitHub Desktop.
This file contains 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 demo.impl.store) | |
(gen-interface | |
:name demo.api.Store | |
:methods [[buy [] demo.api.Store] | |
[buy [int] demo.api.Store] | |
[sell [] demo.api.Store] | |
[getQty [] int]]) | |
(gen-class | |
:name demo.impl.StoreImpl | |
:implements [demo.api.Store] | |
:state state | |
:init init | |
:methods ) | |
;; Implementation functions for StoreImpl | |
(defn -init [] | |
[[] (ref 100)]) | |
(defn -sell [this] | |
(dosync | |
(alter (.state this) dec)) | |
this) | |
(defn -buy | |
([this] | |
(dosync | |
(alter (.state this) inc)) | |
this) | |
([this q] | |
(dosync | |
(alter (.state this) + q)) | |
this)) | |
(defn -getQty [this] | |
@(.state this)) | |
;; A factory for creating a Store. | |
(gen-class | |
:name demo.api.StoreFactory | |
:methods [^{:static true} [makeStore [] demo.api.Store]]) | |
(defn -makeStore [] | |
(demo.impl.StoreImpl.)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment