Hi I am a quite beginner in java.
Is it a good way to create construcors with many parameters like in my BookLibrary program?
public class Book implements Serializable {
private String title;
private String directorName;
private String directorSurname;
private String type;
private int issueYear;
private List<String> actorNames;
private List<String> actorSurnames;
private Tuple<String, String> directorFullName;
public Book(String title, String directorName, String directorSurname, String type, int issueYear,
List<String> actorNames, List<String> actorSurnames, Tuple<String, String> directorFullName){
this.title = title;
this.directorName = directorName;
this.directorSurname = directorSurname;
this.type = type;
this.issueYear = issueYear;
this.actorNames = actorNames;
this.actorSurnames = actorSurnames;
this.directorFullName = directorFullName;
}
Or is there any better idea to create such a constructor?
thisand while setting the fields you can chain such setters. If there are some mandatory fields without which object has no meaning then you can use constructor for such fields and for rest have setters methods or you can also use Builder pattern