Solved

getters and setters in java

Posted on 2013-11-13
5
660 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 26

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java Message handling in Service Layer 3 39
solarwind tftp server 2 32
Unable to start eclipse ? 17 87
JAVA part two 5 42
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now