I am a fan of Martin Fowler (deprecated) presentation model presenter template. I am writing a Scala class class containing several button classes. I would like to include methods for setting the action properties of the buttons that the master calls. A typical piece of code 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 a C preprocessor, I would create a macro to generate this code, given the name of the button (without lectures on the evil C preprocessor, please). This code is obviously very verbose and repetitive. Is there a better way to do this in Scala, possibly using traits?
Read lectures about scala.swing. I am looking for a generic template here.
Ralph source
share