Last active
August 31, 2016 08:46
-
-
Save r-winkler/28a91e6a878049a404d6933ac6ec45c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Airplane { | |
private final int seats; | |
private final int engine; | |
private final int rescue; | |
private final List<Instrument> instruments; | |
private Airplane(Builder builder){ | |
this.seats = builder.seats; | |
this.engine = builder.engine; | |
this.rescue = builder.rescue; | |
this.instruments = builder.instruments; | |
} | |
public static class Builder { | |
private final int seats; | |
private int engine; | |
private int rescue; | |
private List<Instrument> instruments; | |
public Builder(int seats){ | |
this.seats = seats; | |
} | |
public Builder withEngine(int engine) { | |
this.engine = engine; | |
return this; | |
} | |
public Builder withRescue(int rescue) { | |
this.rescue = rescue; | |
return this; | |
} | |
// get child builder and hands over parent builder | |
public Instrument.ListBuilder addList(){ | |
return new Instrument.ListBuilder().setAirplaneBuilder(this); | |
} | |
public void addList(List<Instrument> instruments){ | |
this.instruments = instruments; | |
} | |
public Airplane build(){ | |
return new Airplane(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment