Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

encapsulate data easy question.. begginer

 
slav agui
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am trying to undertand how encapsulate data works.
I have:
TestEncapsulate userdata = new TestEncapsulate (
rs.getString("name")==null?"":rs.getString("name"),
rs.getString("last")==null?"":rs.getString("last"),
rs.getString("midd")==null?"":rs.getString("mid")
) ;
was working, good. But another programmer told me that was missing:
userdata.setname(request.getParameter("name"));
userdata.setlast(request.getParameter("last") );
userdata.setmidd(request.getParameter("midd"));
So I added (and is working too!). He told me to keep it because is necessary.
I do not undertand why do I need to do the second section if in the first section I put the values, isn't it?.
Some body can explain me this, please?
THANK YOU!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure how this is a Struts question.

I suspect the issue the other programmer was talking about is that the JavaBean specification requires getters and setters for bean properties.

Having a constructor that fills all the values is okay, but it's also good practice (and required in many circumstances) to have a default constructor that takes no values, and getters/setters that allow setting and retrieving the bean properties.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic