There are a few forms, and they follow the pattern of Object Oriented Programming and are:
1 - Default with Get / Set:
public class Character
{
private String name;
private int intellect;
private int strength;
private int stamina;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIntellect() {
return intellect;
}
public void setIntellect(int intellect) {
this.intellect = intellect;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
public int getStamina() {
return stamina;
}
public void setStamina(int stamina) {
this.stamina = stamina;
}
}
2 - Pattern with Get / Set + Builder:
public class Character
{
public Character(){ }
public Character(String name, int intellect, int strength, int stamina){
this.name = name;
this.intellect = intellect;
this.strength = strength;
this.stamina = stamina;
}
private String name;
private int intellect;
private int strength;
private int stamina;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIntellect() {
return intellect;
}
public void setIntellect(int intellect) {
this.intellect = intellect;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
public int getStamina() {
return stamina;
}
public void setStamina(int stamina) {
this.stamina = stamina;
}
}
3 - Pattern with Get / Set + Constructor + Fluent Interface
public class Character {
public Character() { }
public Character(String name, int intellect, int strength, int stamina){
this.name = name;
this.intellect = intellect;
this.strength = strength;
this.stamina = stamina;
}
private String name;
private int intellect;
private int strength;
private int stamina;
public String getName() {
return name;
}
public Character setName(String name) {
this.name = name;
return this;
}
public int getIntellect() {
return intellect;
}
public Character setIntellect(int intellect) {
this.intellect = intellect;
return this;
}
public int getStrength() {
return strength;
}
public Character setStrength(int strength) {
this.strength = strength;
return this;
}
public int getStamina() {
return stamina;
}
public Character setStamina(int stamina) {
this.stamina = stamina;
return this;
}
}
How to use:
Following the 3 that contains all the examples follows the code below:
Fluent Interface:
Character ca1 = new Character();
ca1
.setName("Nome 1")
.setIntellect(1)
.setStrength(2)
.setStamina(3);
By the Builder:
Character ca2 = new Character("Nome 1", 1, 2, 3);
Traditionally:
Character ca3 = new Character();
ca3.setName("Nome 1");
ca3.setIntellect(1);
ca3.setStrength(2);
ca3.setStamina(3);