I'd greatly appreciate your thoughts on the following proposal for the B&S project's database layer.
Specified in the SUN's assignment, DBMain interface and Data class, which implements this interface and reads / writes to the database file, can be thought of as the actual data source implementation (similar to RDBMS: MySQL, etc). If we closely look at the methods in the DBMain interface then we can see that they are very generic, ie they have no references to contractors (eg, String read(int recNo) throws RecordNotFoundException ). Therefore, we can assume that DBMain can be used for accessing information not only from Contractor's table but from other tables as well (should they be added to the database file, eg, Customer table). That's why each instance of the Data class is associated with the specific table (tableName is passed as a parameter into the constructor), for which it performs read/write operations. Data class knows how to locate meta information on the table (in fact it will use schema description section in the database file)
In order to access and modify Contractor related data in any data source we create data access object: ContractorDAO interface. This interface defines methods such as:
Our project will contain just one concrete implementation of ContractorDAO interface: FileContractorDAO which in fact provides the means to access Contractor related data in our data source implementation (via Data class)
FileContractorDAO creates an instance of Data class with the Data.CONTRACTOR_TABLE.
Also we'll have a business delegate that will have a local and remote interfaces (too much ejbs in my head ): ContractorBO. This delegate will talk to FileContractorDAO when it needs to access contractor's related data. Business object will perform tasks such as validating user input, booking contractor record, performing searches, etc. The GUI side will always talk to the database layer via ContractorBO.
I think that this design proposal neatly fits into the DataAccessObject design pattern.
Thanks a lot in advance for your comments.
[ August 23, 2005: Message edited by: Alex Sharkoff ] [ August 23, 2005: Message edited by: Alex Sharkoff ]
I was also thinking about using a similar design. It looks very elegant. But now I look at the remote/local database part of the assignment: I wonder if I should implement the DB interface on the local and remote stub, or create a DAO interface and let the remote/local stub implement that interface.Any ideas?
I wonder if I should implement the DB interface on the local and remote stub
Your DB interface probably does not allow you to throw the needed exceptions for you to use it as your remote interface so you are almost certainly going to have to wrap it - don't know if that makes a difference to your decision or not.