Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

getters and setters in java

Posted on 2013-11-13
5
704 Views
Last Modified: 2013-12-10
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
Comment
Question by:gudii9
  • 3
5 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 300 total points
ID: 39646656
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
 
LVL 27

Assisted Solution

by:rrz
rrz earned 200 total points
ID: 39646829
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
 
LVL 7

Author Comment

by:gudii9
ID: 39648830
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
 
LVL 7

Author Comment

by:gudii9
ID: 39667453
Please advise.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39690997
VO and DTO are same right.

BO is for the business entity tables right. Please advise
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example issue 6 46
expectj telnet failing 5 45
hibernate example for saving data 19 54
jsp login check 12 42
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question