This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data Class" Watch "Data Class" New topic
Author

Data Class

Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
My progress has been sluggish in SCJD due to other issues .. but i am going on....
I had a small question in URLYBIRD
I remember discussing once about the data class and the fact that one of the approaches to achieve synchronization is to use the singleton design pattern. By making the data class a singleton, and following other methods, the data class can access multiple threads.The data class implements the given interface.

I also have a value object class which in turn calls methods of the data class. I was wondering if it should be this class which is a singleton instead of the data class. I remember someone saying that the reason Sun gives us an interface is because they use their methods to populate the db. If the Value object class is a singleton, the data class is not going to be thread safe alone. While I can defend my design in the choices.txt saying that the only legitimate way of accessing data class in my program was through the value object class, is that reason going to be satisfying for the sun certifiers ?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Gaurav!

Having a singleton whose all methods are synchronized and only this class accesses the Data class will work too. However, if your Data class is public, then someone might use it incorrectly when maintaining your code, bypassing the class that accesses the Data class.

But, you said that you have a value object... just to clarify: a value object is an object that is immutable, that is, once created, cannot be changed (therefore, its attributes have to be initialized in its constructor method). These objects do not have any inteligence and have a meaning in a particular domain. Are you sure that you really mean value object?


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
Roberto Perillo wrote:Howdy, Gaurav!

But, you said that you have a value object... just to clarify: a value object is an object that is immutable, that is, once created, cannot be changed (therefore, its attributes have to be initialized in its constructor method). These objects do not have any inteligence and have a meaning in a particular domain. Are you sure that you really mean value object?


Well i think i am a little confused. As I understood(i think i am wrong in this), instead of transferring data as a string [] from the database to the view, I encapsulated all the data in an object as mentioned by monkhouse in his Denny's DVD class.

The class which I created is equivalent of the DVD class in Denny's DVD. Please correct me if I am wrong
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

Your value object is not supposed to call methods from Data class. Here the value object design pattern is described.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Interestingly, what Roel showed is what the definition of value object according to the early J2EE literature. They came up in the EJB2 age as an alternative to avoid network overhead. Objects that have no intelligence and only exist to transport data between layers in an application are called Data Transfer Objects, or Transfer Objects.

Martin Fowler describes value objects in his Patterns of Enterprise Application Architecture book. A preview of this description can be seen here.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

Roberto Perillo wrote:Interestingly, what Roel showed is what the definition of value object according to the early J2EE literature.

You are correct. The value object design pattern is nowadays the transfer object design pattern (what's in a name )
 
Consider Paul's rocket mass heater.
 
subject: Data Class
 
Similar Threads
Object adapter design pattern
URLyBird - Question about Singleton pattern
Design questions (with RMI)
Took essay exam yesterday (4th May 2010)
NX: Locking and Unlocking and Sun's Must Conditions