Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use Reify instead of proxy in clojure?

Tags:

clojure

Why should I use Reify instead of proxy in clojure?

like image 917
yazz.com Avatar asked Apr 28 '11 16:04

yazz.com


2 Answers

The method bodies of reify are lexical closures, and can refer to the surrounding local scope. reify differs from proxy in that:

  • Only protocols or interfaces are supported, no concrete superclass.
  • The method bodies are true methods of the resulting class, not external fns.
  • Invocation of methods on the instance is direct, not using map lookup.
  • No support for dynamic swapping of methods in the method map.

The result is better performance than proxy, both in construction and invocation. reify is preferable to proxy in all cases where its constraints are not prohibitive.

Source: http://clojure.org/datatypes

like image 198
KushalP Avatar answered Oct 02 '22 09:10

KushalP


Use reify where you would once use proxy, unless you need to override base class methods.

like image 40
semperos Avatar answered Oct 02 '22 10:10

semperos