Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getters and setters in java

Posted on 2013-11-13
5
Medium Priority
?
796 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 28

Accepted Solution

by:
dpearson earned 1200 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 28

Assisted Solution

by:rrz
rrz earned 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

916 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