Skip to content

Pattern: Decorator

justinmann edited this page Nov 12, 2017 · 3 revisions

The decorator pattern involves a class forwarding to another class for functionality.

#layout(
	measure()
	position()
)

listLayout #layout (
	measure()
	position()
)

// If you want the entire interface implemented by another class
button #layout (
	// Implement the interface using another class
	l: listLayout()
	measure() { l.measure() }
	position() { l.position() }
)

// If you want to partially override another implementation
button2 #layout (
	l: listLayout()
	measure() { l.measure() }
	position() {
		// Override and do my own thing
	}
)

b: button()
l: b as #layout
l.measure()

Clone this wiki locally