Scala model-view-presenter, traits

Posted by Ralph on Stack Overflow See other posts from Stack Overflow or by Ralph
Published on 2010-05-26T16:48:08Z Indexed on 2010/05/26 16:51 UTC
Read the original article Hit count: 245

Filed under:
|
|

I am a fan of Martin Fowler's (deprecated) model-view-presenter pattern. I am writing a Scala view class containing several button classes. I would like to include methods to set the action properties of the buttons, to be called by the presenter. A typical code fragment looks like this:

private val aButton = new JButton
def setAButtonAction(action: Action): Unit = { aButton.setAction(action) }

This code is repeated for each button. If Java/Scala had the C preprocessor, I would create a macro to generate this code, given the button name (no lectures on the evils of the C preprocessor, please). This code is obviously very verbose and repetitive. Is there any better way way to do this in Scala, perhaps using traits?

Please hold the lectures about scala.swing. I looking for a general pattern here.

© Stack Overflow or respective owner

Related posts about scala

Related posts about macros