/ Published in: Groovy
Decorator design pattern implemented in Groovy, two implementation are provided, the first is naive and not general, the second is MOP based and can be used in much more scenarios.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// the decorated class package design.patterns.decorator class Logger { } } // the naive implementation package design.patterns.decorator def logger LowerCaseLogger(log) { logger = log } logger.log(text.toLowerCase()) } logger.log('HELLO DECORATION') } } // the more general implementation package design.patterns.decorator class GenericLowerLogger { private delegate GenericLowerLogger(delegate) { } } } logger.log('HELLO DECORATION')// hello decoration } }