This question is more about a good practice to avoid code duplication when validating input data.
The application imports a spreadsheet (XLS or XLSX) and instantiates an OrderList
Object, which contains multiple OrderUnits
(referring to each row of the original spreadsheet).
The user is able to alter some properties, also those, which have not been set via the import spreadsheet.
In other words the import feature forms a base of data, which will then be extended by the user. Some properties even are set automatically (e.g. if the length of an orderUnit is greater than 5.0 metres, the material will be set to steel, instead of default plastic.).
The is a json configuration file, where all properties of an orderunit can be defined, including fields like type (string, decimal, list) and validation (not_blank,...).
To my question: Because there are two methods of inserting data, where is a good place to validate the data, before the orderUnit property gets set?
One place is the import of data, which completely takes place in my
OrderUnit
model class I could use some custom validation mechanism.The other place is via the
JTextComponents
which can be set or altered after the import has taken place. I would like to useInputVerifier
on everyJComponent
.
But this leads to duplicate code of my validation creteria.
Is there a nice way to validate once or at least reuse the same validation model twice?