I am writing an application for different geometrical types of fuel tanks.
I have a design problem that only at runtime I will receive the exact type of tank from the end user; and I don't know how to create/handle a dynamic object on the server side.
For example, a tank can have 3 geometrical types of head: conical, dished, and flat. Each type of head needs to be validated differently.
I have created a parent class named Head
that has all common parameters to all geometrical types of head (diameter, thickness etc.). Each child class (Conical
, Dished
and Flat
) extends Head
and has its own instance variables.
The end user will choose, for example, a tank with conical heads and input all the required parameters and send it to the server for validation.
At this stage I am stuck. I don't know how to handle the dynamic data. I got a suggestion to use Factory design pattern; but because every class has different variables, I don't think that is the right direction.
code without constructor and get/set methods
public class Head {
private float headThickness=0;
private float headThicknessTolerance=0;
private ShapeOfHead headShape;
private float knuckleRadius=0;
private int numberOfHeadPieces=4;
private HeadSide headSide;
private Figure8_1WeldingDetails headLongitudinalWeld;
private Figure9_1WeldingDetails headCircumferentialWeld;
private Bracing headBracing;
}
public class DishedHead extends Head {
private float dishedHeadDepth;
}
public class ConicalHead extends Head {
private float conicalHeadHeight;
}
type
field within the data typed in. You use it to differentiate the Child classes for Head. Once you have the new object, you can forward all input data. The object will know how to use the input data, because it's dedicated data for that particular class. But this seems too simple. Maybe I'm overlooking something.