Thanks,

This works, but there's a problem: the labeledtextfield is not a
textfield anymore, it's a label. Therefore it does not behave like a
textfield (which implements other protocols as well). I need multiple
inheritance, in one way or another. I've been trying to find a way to
implement with multimethods.

For example, if label was a mixin, then it means I could do something
like this:

(def textfield (new TextField "Foo")
(def labeledtextfield (new (mix TextField Label) "Name" "Foo"))

(render textfield) ;=> [Foo]
(render labeledtextfield) ;=> Name: [Foo]

Oh, and I'd like to stay away from macros, if possible. :)

Razvan

On Feb 6, 12:20 pm, Matthias Diehn Ingesman <matdi...@gmail.com>
wrote:
> It sounds a little like the decorator pattern would do the trick for
> you in this case - am I missing something? In case I am not, I have
> given it a shot using records and protocols:
>
> (defrecord TextField [text])
> (defrecord DatetimePicker [datetimes])
> (defrecord Label [text widget])
>
> (defprotocol Renderable
>   (render [this]))
>
> (extend-protocol Renderable
>   TextField
>   (render [this]
>     (str "[" (:text this) "]"))
>
>   DatetimePicker
>   (render [this]
>     (apply str (:datetimes this)))
>
>   Label
>   (render [this]
>     (str (:text this) ": " (render (:widget this)))))
>
> (comment
>   (def textfield (TextField. "Foo"))
>   (def datetimepicker (DatetimePicker. [:yesterday :today :tomorrow]))
>   (def labeledtextfield (Label. "Name" textfield))
>   (def labeleddatetimepicker (Label. "Date" datetimepicker))
>   (render textfield) ;=> [Foo]
>   (render datetimepicker) ;=> :yesterday:today:tomorrow
>   (render labeledtextfield) ;=> Name: [Foo]
>   (render labeleddatetimepicker) ;=> Date: :yesterday:today:tomorrow
>   )
>
> 1/ is handled by the Renderable implementation for Label calling the
> Renderable implementation on whatever widget it decorates with a
> label.
>
> 2/ is handled by having the Label decorator widget as a record.
>
> Regards,
>  Matthias

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to