• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

The Data class in URLyBird...

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Mark!

Champion, in my opinion, this is more of an API decision. I'd say that, as long as everything is done correctly beneath the API (which is the interface provided by Sun), then it is really up to you. Of course, the less duplicate code, the better. So, if you are able to create generic methods and ease the implementation of the Data class, go ahead! And, also, try to avoid procedural code.
 
Mark Blackwood
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roberto . I thought of another (trivial) question, and posted it here, but realized it was pretty much self-answering and removed it!
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic