I would like to create small service with for example shapes...
Shape request model will looks like:
public class ShapeRequestModel {
private String type;
private List<Double> parameters;
}
I created abstract Entity Shape and other Shapes inheritance after that:
public ShapeEntity createShape(ShapeType type, List<Double> parameters) {
switch (type) {
case CIRCLE:
return circleEntityRepository.saveAndFlush(new CircleEntity(parameters));
case SQUARE:
return squareEntityRepository.saveAndFlush(new SquareEntity(parameters));
case RECTANGLE:
return rectangleEntityRepository.saveAndFlush(new RectangleEntity(parameters));
default:
throw new IllegalArgumentException();
}
}
I do not know if creating multiple tables is the best solution. On the one hand my objects do not have the same amount of parameters (for example, rectangle has width and height, circle - has only radious). but on the other hand I could hold everything in database in one row: for example id / type / list of parameters as a json.