UJO Framework为对象提供了一种有别于JavaBeans的架构。最初的想法来源于Java5.0的范型。但是,随着时间的流逝,这种架构表现一些激动人心的特性:
代码示例:
import java.util.HashMap; import org.ujoframework.*; import org.ujoframework.core.UjoManager; import org.ujoframework.implementation.map.*; @SuppressWarnings("unchecked") public class Person implements Ujo { public static final MapProperty NAME = new MapProperty("Name", String.class); public static final MapProperty MALE = new MapProperty("Male", Boolean.class); public static final MapProperty CASH = new MapProperty("Cash", 0d); // --- The start of the MapUjo implementation --- private HashMap map = new HashMap(); public Object readValue(UjoProperty property) { Object result = map.get(property); return result!=null ? result : property.getDefault(); } public void writeValue(UjoProperty property, Object value) { map.put(property, value); } public UjoProperty[] readProperties() { return UjoManager.getInstance().readProperties(getClass()); } public boolean readAuthorization(UjoAction action, UjoProperty property, Object value) { return true; } // --- The end of MapUjo implementation --- /** Add cash in the **Ujo implementation** */ public void addCash(double cash) { double newPrice = CASH.of(this) + cash; CASH.setValue(this, newPrice); } }