/ Published in: Groovy

Mediator design pattern implemented in Groovy (based upon http://www.javacamp.org/designPattern/).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// The mediator class which connects all the colleges (buttons in this case) // and updates them all in reaction to informations from any of them package design.patterns.mediator def show buttons << b } show = d } buttons.each { } else { } } show.setText(text) } } // The demo UI which demonstrates the usage package design.patterns.mediator.ui import groovy.swing.SwingBuilder import design.patterns.mediator.Mediator panel() { label(text: 'just starting') {mediator.registerDisplay(current)} button() { mediator.registerButton(current) action(name: 'view', closure: {mediator.mediate(current, 'viewing ..')}) } button() { mediator.registerButton(current) action(name: 'book', closure: {mediator.mediate(current, 'booking ..')}) } button() { mediator.registerButton(current) action(name: 'search', closure: {mediator.mediate(current, 'searching ..')}) } } } frame.setSize(400, 200); } }
Comments
