I thought in the Contractor assignment that there is a primary key. It was the Contractor name in my Beta, but even if that is no longer, the contractor name and location would still make up a primary key. I'll agree that name + location
could be used as a primary key, but the instructions provide very little info to support this. Here's all I have found to support the idea that name + location should be a primary key:
As noted, the create() method is listed as "throws DuplicateKeyException". No further explanation; the only other place the word "key" appears in the instructions is in the phrase "There are three key parts...".Under "The User Interface", we are told: "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user." Indicating a special status for name and location. But no indication that this combination needs to be unique.Examining the included DB file itself, it appears that while name is not unique, and location is not unique, name + location is indeed unique for included entries. There's one more factor which is outside the instructions completely - our "common sense" tells us that a database should have some sort of primary key, other than the record number. Well, maybe so, but my common sense tells me Bodgitt & Scarper will eventually need a lot of other things too, if this were to become a serious database system. I keep having to remind myself (or be reminded by others)
that those things aren't actually required for this assignment.
The case against implementing a uniqueness constraint on name + location, IMO, is:
It's never explicitly required.It's more work.It would add complexity. (Not necessarily a huge amount, it could be isolated, but still...)It would decrease performance. (Again, not a big concern, but it's there.)The update() method does not throw DuplicateKeyException, even though it's fully capable of changing the name and location fields. I suppose that it's less necessary here because a competent programmer can simply avoid ever changing those fields in an update - while for create() they have to provide values, and don't know if those values are already in teh DB or not. (Even a find() is insufficient to make any guarantees here unless you block all other create() calls between the find() and your create(). Possible but icky.) Still, failure to address the update() issue is a big indicator (for me) that whoever wrote the DuplicateKeyException part of the API was probably on crack. The DB file header does not provide any way to indicate primary keys. If we ignore possibility of primary keys, then the Data class can provide nice generic access to any file implementing the given format - not just B&S contractor info. Adding a uniqueness restriction would thus limit reusability of the Data class.The GUI client we're actually delivering here is not capable of doing any create(), or update() of any field other than client ID, so there's no possibility of actually creating any duplicate keys with this software. If some future enhancement needs to make use of the create() and update() methods, then at that time someone can get B&S to clarify what they really wanted, and make modifications to the Data class (and hopefully DB as well) if necessary. So - while it seems very plausible that enforcing a unique primary key might be a future enhancement, I don't think it's necessary, or even a good idea, to do it now.
[ July 29, 2003: Message edited by: Jim Yingst ]