• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

set and get methods

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
Any body have an idea of how to implement set and get methods. I am douting about how the set and get methods be written in a class. Should both methods be used in a constructor or in the main.
Note: I want my main to be in another file.
Hope to hear from any body who have experience this problem before.
Bye for now Samuel.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Samuel,

This pattern is called as Value Object, Example is as follows

public class EmployeeVO
{
private String name;
private String employeeid;

public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setEmployeeID(String employeeid)
{
this.employeeid=employeeid;
}
public String setEmployeeID()
{
return employeeid;
}
} // No main method is present here

Ideally you extract the data from a request object in the web tier, create a instance of the above EmployeeVO and assign the data using the setter methods and send the EmployeeVO object as the parameter to the Data Acess Tier.In Data Acess Tier its retrived using gettter methods.

Sameway when you retrive data from a database the same process is done and the EmployeeVO object is sent to the Web Tier

Dont write getter and setter methods in an EJB, its a costly deal !

This pattern is also out dated ... you can use Transfer Object, Its quite the same except that it has only member variables (No getter & setter methods) would say its not encapsulated. For more details on this refer www.corej2eepatterns.com

Hope this helps.

- Senthil
 
Senthil Rajendran
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
small correction

public String setEmployeeID() // signature should be getEmployeeID
{
return employeeid;
}
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this discussion to "Java in General (intermediate)" forum.
 
reply
    Bookmark Topic Watch Topic
  • New Topic