In my design there is one DataShema class, that contains the information and the structure of the database file. I read the database schema, the name of every field in the database during the initialisation of the DataShema class. This class is the Singleton. It contains one static method:
My interface that specified all methods that will be remotely called by the client contains one method, that returns an array of the name for every field:
All business logic is implemented in the DataAdaptor class. This class implements the getHeaderNames():
I didn�t throw any exceptions during the call of the getHeaderNames, any IOException, because the names will be read only ones during the Initialisation. How do you think is this a good design? Or should I read the fields� names every time when I call the DataShema.getFieldsName() method? Thanks a lot for your comments and help! Regards, Olena.
I didn’t throw any exceptions during the call of the getHeaderNames, any IOException, because the names will be read only ones during the Initialisation. How do you think is this a good design? Or should I read the fields’ names every time when I call the DataShema.getFieldsName() method?
My questions to you (which I suspect you already know the answer to) are: when can the field names change? and/or do you have any methods which will allow the field names to be changed.
If the field names cannot be changed, then it seems to be more efficient to cache them (as you are doing) rather than re-reading them each time someone calls the getFieldsName() method.
I have also a DataScheme implementation.Here I read the file header on initialization(read in the contructor) and if there are problems(the file has a wrong cookie or its schema can not be interpret it) some exception raises. For the rest I cache the scheme information because this are often used datas(and are not so big). Now about the exception and the constructor - I know this is not a good technique but it keeps the code simple.Like alternative I can use an init method(and raise all the exception here) but I still think about.
If your DataScheme is a singleton and you access it via one of its "global point of access to it" can you change the scheme runtime ? Let's say that you use data base A (with scheme A) and you try to change the database B (with scheme B, A != B).If your scheme is a singleton (only one instance) you can not use the database B - or you must create a singleton every time when you "choose" the database file.