Skip to content

Instantly share code, notes, and snippets.

@david-mcneil
Created June 12, 2010 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-mcneil/435822 to your computer and use it in GitHub Desktop.
Save david-mcneil/435822 to your computer and use it in GitHub Desktop.
(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