• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJD (Apress)

 
PaulSeldon07
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Yingt at JavaRanch,

I have a question. I'm reading the SCJD from Apress.com.
At the page of 143 - 144,

private DVD retrieveDVD(long locationInFile ) throws IOException {


Class RecordFieldReader { } //as a inner class, and
RecordFieldReader readRecord = new RecordFieldReader();


}, which read a DVD and return


What is the benefit of designing like the above?
I am looking at each record, the class has to be redefined and get a instantiated.
So, if I have million records, I have to define the inner class milliontimes and instantiate
this class million times. If the benefit of design like this surpasses my concerns
written above, I would like to know exactly.

Would you be kind enough to explain to me?
It would be really appreciated. Thanks -

---Paul Seldon
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent seen the book so I can't really comment on the thought behind the design. However if I was reading a million records I would be much more concerned about the IO overhead of these operations (I doubt you will ever be using a flat file db to deal with a million clients). The time it would take initialise an inner class each time is very small in relation to this.

Mark
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Could you please take another look at the JavaRanch official policy on displayed names, which you agreed to when you joined JavaRanch? Please adjust your displayed name so that it appears real (not doubled up). You can adjust it here.

The primary benefit of the way we wrote that code is that it keeps the inner class together with the method that uses it. This helps with readability and maintainability.

Paraphrasing Mark, if performance were an issue, then I would use a professional tool to work out where the performance bottleneck was, then fix that particular area.

There might be a performance gain in refactoring that particular bit of code, but without knowing if that were the code that causes the bottleneck, I could end up wasting my time in fixing the wrong problem.

Oh - and a side not to Mark. Some site that we all visit has nearly 150,000 registered users (which means that there are a far greater number of users since you don't need to be registered to view articles), and I suspect over 1/2 million topics, most with multiple replies, all working off flat files. It is possible

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic