I'm creating a Data Access Layer (DAL) to read/modify some tables stored in an XML file. While my application is running, the rows of these tables are updated very often, therefore I thinking about two possible alternatives:
Dictionary
. While the application is running, this dictionary is continuously updated. When the application is closing, I invoke a method of the DAL in order to overwrite the old file with the new data in the dictionary.Dictionary
private field in the DAL. In this way, the upper layers would call the methods of the DAL to update the rows of the tables.Is perhaps the second approach better than the first one?
Option 2 here is better for encapsulation though does increase complexity. The dictionary is an implementation detail that your upper levels shouldn't be concerned with. Instead your data access layer should expose classes that represent the actual tables - for example you may have a Person
class or an Inventory
class. As DAL classes these would provide methods for adding, deleting, updating, retrieving etc. as appropriate.
Further up you'd have a domain layer which operates on a row retrieved from your DAL classes that would add business methods (e.g. an Order
could be made by a Person
and impacts Inventory
- the act of invoking methods on these domain classes goes down to the DAL to actually touch the underlying data).