Skip to content

Instantly share code, notes, and snippets.

@vepo
Created July 8, 2022 12:55
Show Gist options
  • Save vepo/949a640164e87632459f7f0dc9191d4e to your computer and use it in GitHub Desktop.
Save vepo/949a640164e87632459f7f0dc9191d4e to your computer and use it in GitHub Desktop.
public class Car {
public static CarBuilder builder() {
return new CarBuilder();
}
public static class CarBuilder {
private CarType type;
private int seats;
private Engine engine;
private Transmission transmission;
private TripComputer tripComputer;
private GPSNavigator gpsNavigator;
private CarBuilder() {
// inicializa valores default
}
public CarBuilder type(CarType type) {
this.type = type;
return this;
}
// segue o padrão
public Car build() {
return new Car(this);
}
}
private CarType type;
private int seats;
private Engine engine;
private Transmission transmission;
private TripComputer tripComputer;
private GPSNavigator gpsNavigator;
public Car() {}
public Car(CarBuilder) {
// inicializa todos os valroes
}
// getters, setters, hashCode, equals e toString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment