class item {public item(String x) { _name = x; _self = null; } String name() { return exists()?self().name():_name; } public void redirect(item x) { _self = x; } boolean exists() { return _self != null; } public item self() { return exists()?_self.self():this; } item _self; String _name; };
item
public class go { public static void main(String[] args) { item a = new item("a"); item b = new item("b"); a.redirect(b); System.out.println(a.name());indeed, b
} };
Those well-versed in design patterns will recognize the Decorator
patterns (as applied in the Interviews MonoGlyph class,