• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data Class

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your value object is not supposed to call methods from Data class. Here the value object design pattern is described.
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 )
reply
    Bookmark Topic Watch Topic
  • New Topic