Java Reference
In-Depth Information
public void removeStaticProperty(String name, Object value) {
staticProperties.remove(name);
}
public void addInstanceProperty(String name, Object value) {
instanceProperties.put(name, value);
}
public void removeInstanceProperty(String name, Object value) {
instanceProperties.remove(name);
}
public boolean isInstanceProperty(String name) {
return instanceProperties.containsKey(name);
}
public boolean isStaticProperty(String name) {
return staticProperties.containsKey(name);
}
public Object getStaticProperty(String name) {
return staticProperties.get(name);
}
public Object getInstanceProperty(String name) {
return instanceProperties.get(name);
}
}
NOTe If you're up for a challenge, try making a general type class support-
ing static, instance, public, private, and final fields. In addition, try creating a
Typeable interface that any class can implement and then add your custom
typing functionality on top of it.
Next, rework the Product class:
import java.util.HashMap;
import java.util.Map;
public class Product {
private double price;
private String name;
private ProductType type;
private Map<String, Object> instanceProperties;
public Product(String name, double price, ProductType type) {
this.name = name;
this.price = price;
this.type = type;
this.instanceProperties = new HashMap<>();
}
Search WWH ::




Custom Search