Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Value objects  RSS feed

 
rakesh kesavan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me the basics about the value objects in java..i mean the set() and get()
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rakesh kesavan:
please tell me the basics about the value objects in java..i mean the set() and get()


I think you're referring to a Plain Old Java Object (POJO). Good OO designs tells you that you should have private attributes with public accessor operations to act on them. Hence, getters & setters (or whatever names you like) are the public accessor methods that would act on the private attributes.

For each private attribute, you could have a pair of getter & setter methods. However, if that attribute is meant to be read-only, then you won't need a public available setter method. You could populate the value through the constructor of the POJO.

A value object (VO) or transfer object (TO) is a design pattern. Normally, POJOs are used to implement VO/TO. Usually, you would query your database for some data & convert them into a POJO, and transfer it over the network, to be presented at the view-tier. The advantages of using a TO/VO is that you minimizes network traffic by aggregating similar attributes into an object. So instead of having so many roundtrips to fetch individual attributes, you do so with a single trip to transfer a POJO over.

Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!