Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Mark Blackwood

Greenhorn
+ Follow
since Feb 04, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Blackwood

Thanks Roberto . I thought of another (trivial) question, and posted it here, but realized it was pretty much self-answering and removed it!
Actually, this question appears to have already been answered in the topic entitled "Data class and facade"... Sorry, should have read first!

Howdy ranchers,
This isn't really a mater of life or death question, but I was hoping I could have your opinions anyway. In the data class, it strikes me that there are basically 2 primary concerns (reading and writing blocks of data), and that the locking mechanism is just there to ensure that these things happen safely.
Create, update and delete all write blocks of data to the database file. Find and find by criteria read blocks of data. A lot of the code in these methods will probably be the same.
So I was thinking, why not have a generic, private read method and a generic private write method, each of which is called with a set of specialized parameters by the methods in the interface to do only that particular job (i.e. to tell it what to write or read and where), to avoid code duplication?
But then I noticed that some of the read and write methods throw different exceptions. so which of the following should I do:

1. Just have implementations of the methods in the interface, which do everything required for their own job entirely, and don't have any generic private methods. This might involve some code duplication.
2. Work out whether security, record not found or duplicate key exceptions need to be thrown and throw them in the implementations of the interface methods, which then call the generic private read and write methods.

I have to say I'm inclined towards 2, and accept that this question probably wasn't worth asking, but would like to hear any opinions if anyone has any?

Cheers,

Mark


Sorry, I think my question's been answered above... Deleted!