Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the first option is better. It's more extensible, depending how these objects are going to be used. It's easier to add or change a new function that works on an existing object if the functions and objects are separate. In Clojure there usually isn't much reason to bundle functions along with the objects they work on, unless you really want to hide implementation details from users of your code.</p> <p>If you're writing an interface for which you expect many implementations, consider using <a href="http://clojure.org/multimethods" rel="nofollow noreferrer">multimethods</a> also. You can have the default throw a "not implemented" exception, to force implementors to implement your interface.</p> <p>As <a href="https://stackoverflow.com/users/47623/gutzofter">Gutzofter</a> said, if the only reason you're considering the second option is to allow people not to have to type a parameter on every function call, you could consider having all of your functions use some var as the default socket object and writing a <code>with-socket</code> macro which uses <code>binding</code> to set that var's value. See the builtin printing methods which default to using the value of <code>*out*</code> as the output stream, and <code>with-out-str</code> which binds <code>*out*</code> to a string writer, as a Clojure example.</p> <p><a href="http://blog.thinkrelevance.com/2009/8/12/rifle-oriented-programming-with-clojure-2" rel="nofollow noreferrer">This article</a> may interest you; it compares and contrasts some OOP idioms with Clojure equivalents.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload