Skip to content

Instantly share code, notes, and snippets.

Last active August 31, 2016 08:46
What would you like to do?
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