What would be better programing practice ?
In this example I have class Person and PersonDisplay.
class Person{
private String name;
private String surname;
private String adress;
private String nickname;
private String sex;
private Int age;
private String email;
... and other attributes that i need for something else
public Person(String name, String surname, String adress, String nickname, String sex, String age, String email){
this.name =name;
this.surname = surname;
...
}
}
Should I implement PersonDisplay like this:
class PersonDisplay{
private TextField nameText;
private TextField surnameText;
private TextField adressText;
private TextField nicknameText;
private TextField sex;
private TextField age;
public PersonDisplay(String name, String surname, String adress, String nickname,String sex,int age){
nameText.setText(name);
surnameText.setText(surname);
...
}
}
Or like this
class PersonDisplay{
private Person person;
private TextField nameText;
private TextField surnameText;
private TextField adressText;
private TextField nicknameText;
private TextField sex;
private TextField age;
public PersonDisplay(Person person){
this.person=person;
nameText.setText(person.getname());
surnameText.setText(person.getsurname());
...
}
}
1.What is better constructor implementation?
2.Would using something else like build pattern here be recomended?
Aucun commentaire:
Enregistrer un commentaire