File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Should Data class be a singleton and have all method synchronized? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Should Data class be a singleton and have all method synchronized?" Watch "Should Data class be a singleton and have all method synchronized?" New topic
Author

Should Data class be a singleton and have all method synchronized?

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Hi, I read some of the old posts in the forum.
Someone suggested making Data class a singleton and synchronized all its methods.
In the requirement, it does not say this.

So, can I use Monkhouse book's approach to make Data class a facade?

In Monkhouse book , the DvdDatabase class is a facade and it is not a singleton to my understanding. In DvdDatabase class, there are two static objects of ReservationManager and DvdFileAccess. Only one instance of each of them is created and all methods in ReservationManagers and DvdFileAccess are made to be thread safe (by synchronizing blocks of codes or using lock).

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

That's all up to you!


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Guillaume Drouet
Ranch Hand

Joined: Apr 16, 2012
Posts: 36
In my assignement, the Data class is not a singleton. I have justified it by explaining that my Data class could be reused to manage another kind of records in a second data file. Moreover, the Data class methods are not synchronized. I simply used synchronized blocks within the methods only when it was necessary to make the Data class thread safe. My choices are inspired from what I read in the Monkhouse book.

However, I don't know if I'll get full credit : I have submitted my assignments two days ago and I'll sit for the essay Thursday ;)

I also think that the different options are possible, we just need do justify it in our choices.txt file.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Guillaume Drouet wrote:I'll sit for the essay Thursday ;)

Good luck, champion! I'm convinced you'll pass with flying colours
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Should Data class be a singleton and have all method synchronized?