Properties

The Retarded Property Pattern, Part of "Bad Code"

/**
 * Dear original author: DIAF. --Ed.
 */
class ItemProperties {
    /**
     * Why would any of these be documented? --Ed.
     */
    public static enum ItemProperty {
        COLOR, SIZE, LENGTH, WIDTH, HEIGHT, ADD_LINK, REMOVE_LINK, ALL_LINKS
    };

    private Map<ItemProperty, Object> props;

    private Map<String, Link> links;

    public ItemProperties() {
        props = new HashMap<ItemProperty, Object>()
        props.put(ItemProperty.COLOR, "red"));
        props.put(ItemProperty.LENGTH, 17));
        // ... and so on

        links = new HashMap<String, Link>();
    }

    public void setProperty(ItemProperty p, Object value) {
        switch(p) {
        case ADD_LINK:
            Link link = (Link) value;
            links.put(link.getName(), value);
            break;
        case REMOVE_LINK:
            links.remove(link.getName());
            break;
        case ALL_LINKS:
            links = (Map<String, Link>) value;
            break;
        default:
            props.put(p, value);
        }
    }

    public Object getProperty(ItemProperty p) {
        switch(p) {
        case ADD_LINK:
            return null;
        case REMOVE_LINK:
            return null;
        case ALL_LINKS:
            return links;
        default:
            return props.get(p);
        }
    }
}