I need to avoid duplicate code with these constructors, so I wondered if there is a way to instantiate these variables only ones? I saw a lot of posts about chaining but I haven't gotten it to work properly.
class Trainingsschema
{
// create an arrayList for every oefening
private String klant;
private String trainer;
private Integer nummer;
private ArrayList<Oefening> alleOefeningen;
// two different constructors to correctly initialise the class variables
public Trainingsschema(String klant, String trainer)
{
this.klant = klant;
this.trainer = trainer;
this.nummer = this.volgendUniekNummer();
this.alleOefeningen = this.initialiseerOefeningen();
}
public Trainingsschema(String klant)
{
this.klant = klant;
this.trainer = null;
this.nummer = this.volgendUniekNummer();
this.alleOefeningen = this.initialiseerOefeningen();
}