Created
July 8, 2022 12:55
-
-
Save vepo/949a640164e87632459f7f0dc9191d4e 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 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