execute code in java fields
I'm in a position where I have referenced a static field variable to a
custom class. I need to make alterations to the variable with methods from
the class it references. I can not instantiate the class under
construction. Simplified example:
public class House {
private static MaterialsRequired matsReq = new MaterialsRequired();
private String size;
private House(String size) {
this.size = size;
}
public static MaterialsRequired getMaterialsRequired() {
}
public static void Build(String size) {
new House(size); //Do I need to put 'this(size)' here?
//some code here to expend the materials required factored based on size.
}
To construct the house I need to know the materials required (for standard
size). To know the materials required I need to call the addMaterial()
method of MaterialsRequired. What do I do?
EDIT: I need to call the addMaterial() method repeatedly on matsReq. Maybe
ten times. When I call House.build() I want the matsReq to have been
altered by method calls (if my question was unspecific). Also it doesn't
satisfy me to just set the materials required every time the build() or
getMaterialsRequired() methods are called.
No comments:
Post a Comment