• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 850
  • Last Modified:

getters and setters in java

Hi,

I was going through below link on the design patterns

http://npsakthivel.blogspot.com/2012/05/j2ee-po-bo-vo-dto-pojo-and-dao-concept.html


Based on my experience with these various design patterns and java programming most of it boils down to bunch of getters and setters. why java uses so heavily getters and setters. what is the mechanism and real purpose of these getters and setters.
which design pattern does not use getters and setters


VO ( Value Object )
The ViewObject performance layer object corresponds to the interface to display data objects. For a WEB page, or SWT, SWING interface, with a VO object corresponding to the value of the entire interface.


Is the VO is confined to performace layer only?

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
  • 3
2 Solutions
 
dpearsonCommented:
Personally - I would say that code that uses a lot of setters on objects is rather 'old school' today and that pattern should be avoided.  It was common a few years ago.

The better pattern is to have:
a) A constructor
b) A lot of final member variables
c) Getters for those member variables

This creates an "immutable object" which is now much preferred when building multithreaded programs (which are increasingly common).  They are also easier to use in general.
http://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html

However, this pattern tends to work against the DAO style of database persistence, where you often would get an object from the database and then modify that object and ask a framework (like Hibernate) to them write the modified object back into the database.

The newer style of thinking (at least in my opinion) is that you would not modify the DAO object.  Instead you would create a new object (based on the old one) and then persist that new object by writing it to the database.  This is more the style of newer frameworks like mybatis.

Hope that helps,

Doug
0
 
rrzCommented:
why java uses so heavily getters and setters. what is the mechanism and real purpose of these getters and setters
 
I think it is because of Javabeans.   Javabeans go back almost to the beginning of Java.
A Java Bean is just a standard
1.All properties private (use getters/setters)
2.A public no-argument constructor
3.Implements Serializable.

That's it. It's just a convention. Lots of libraries depend on it.  
 
I cut and pasted that from    that other site.  
Also look at http://en.wikipedia.org/wiki/JavaBeans
0
 
gudii9Author Commented:
Entity and the VO:
Entity with the Identity, the VO did not take the Identity that is Entity only transaction Identity considered as different objects, but as long as the VO attribute is changed, it is regarded as a different object


what is the difference and relation between entiry and VO is not clear to me.

The DTO ( Data Transfer Object )
Mainly used in place of the remote call and need to transmit large amounts of objects.
For example, our one table has 100 fields, then the corresponding PO has 100 properties.
Our interface as long as 10 field, the client access to information, WEB service does not require the PO object passed to the client.
That can use only 10 attributes DTO to pass the results to the client, so would not be exposed to the service end of the table structure. To reach the client, if this object to the corresponding interface display, and that its identity into the VO

I did not get what author trying to explain about DTO either. When he say table is it UI table component or database table?

Our interface as long as 10 field, the client access to information, WEB service does not require the PO object passed to the client.

what author meant by web service does not require PO object passed to client??? Please advise
0
 
gudii9Author Commented:
Please advise.
0
 
gudii9Author Commented:
VO and DTO are same right.

BO is for the business entity tables right. Please advise
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now