• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

modify method in Data

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
modify(DataInfo record) uses find() to verify that the record being modified is indeed the same as the record parameter. If find() returns a record and the record numbers match, the record is OK to update.
But what if find returns null? A new, unique record will be created. Is that OK?
Functionally speaking, this is fine -- a new record gets written somewhere out beyond the current end of the file, and a new end of the file is set accordingly.
Logically speaking, should modify() be revised to disallow its ability to add a new record?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same sort of thing for delete(DataInfo record)... if seek() puts the file pointer out in space somewhere, a deleted-record indicator is written.
Does anyone have thoughts on modifications to these methods? Should delete() balk about deleting records that do not already exist, or about deleting records that have already been deleted?
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't modify any of those methods and lost only 2 points in the server side. I guess it doesn't hurt to change them.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
except for the deprecated methods, I'd highly suggest not changing any of their pre-written code.
Mark
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your feedback. I'm weighing my desire to futz with their code versus my desire to avoid a spanking when they grade the assignment.
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been struggling with this same issue. There are multiple bugs in Data; it seems kinda wierd that we'd know enough to design the added functionality, but that we wouldn't go and fix an obvious bug. The delete case is particularly worrying me; the method actually violates the contract of the invariant. Next time you call a method, *bang*, RuntimeException.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well luckily you don't need to delete any records.
Your assignment does not state to fix any bugs that you might think are in the Data class.
Mark
 
Adam Caldwell
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note it as a design decision that you didn't fix it and leave it at that.
-Adam
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noting it as having been observed, and opting not to fix it is good advice -- far less risk. I'm feeling saucy though and may tear it up all the same. The change could be justified by stating that the interface was not as narrow as the method names would imply. The savvy power user could employ modify() to add new records, for example.
 
Hugo van Elk
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Erick
You are right, I observed this behaviour too.
I think from a technical point of view, the best thing would be to check that the record number in the parameter DataInfo has a value between 1 and getRecordCount().
But I want to touch the code as less as possible, so I'm still in a doubt too. Now that we know this behaviour, we can avoid it:
do the validity check youself before invoking modify or delete.

/Hugo.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hugo -- a passive/aggressive approach, and a very good idea!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic