I am working on URLyBird for my
SCJD exam. And I have on question on modelling the records saved in database.
I have read the schema from provided database file, and it matches the schema provided in the instruction and I am able to read all the data. But comes to modelling of the records saved in the database I have two options, which I am not sure which one to choose.
1. Model it as a POJO
This is most straighforward way, I can create a Record class with all necessary fields, e.g. name, location, size... and pass all the necessary values in to the object, persist in the file.
But doing so is obviously rigid, and defeats the purpose having the schema up front.
2. Model it as a list of FieldValue
Another option I have is to create a class of FieldValue, which holds the flag, name and value of the field. And each record will hold a list of FieldValues.
This approach is more flexible, and honor the schema declared. However, the requirement reads:
A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient. Code complexity, including nesting depth, argument passing, and the number of classes and interfaces, should be reasonable.
Actually I am 80% percent sure that approach 1 should be the way to go, but I wanna play safe and seek further confirmation from the forum.
Thanks a lot.