1. The builder mode means to construct (assign) the parts of an object at 1.1 points, like building a house on a site, which part of the brick is to be set up in a single way, otherwise the default bricks are used.
2. Here is a car class, the car class contains several of its own corresponding properties, its object will be created with some default values. But we can call the Builder class object of the car class as needed to assign a value to the specific property of the car object.
This means that there will be a builder class in the car's interior, which uses the builder pattern to create the method, and his method will return the builder object, so that the assignment method in the Builder object can be constantly called to make a concrete build of the car object.
Public classCar {PrivateString name; Private floatSpeed ; Private floatPrice ; PublicCar () {//car sets parameters when initializing This. Name = "Car"; This. Speed =102f; This. Price =1000f; } @Override PublicString toString () {return"car{" + "name=" + name + "\" + ", speed=" + Speed + ", price=" + Price + ‘}‘; } Public Static classBuilder {PrivateCar MCar; PublicBuilder () {MCar=NewCar (); } PublicBuilder setName (String name) {Mcar.name=name; return This; } PublicBuilder Setspeed (floatSpeed ) {Mcar.speed=Speed ; return This; } PublicBuilder Setprice (floatPrice ) {Mcar.price=Price ; return This; } PublicCar Build () {returnMCar; } }}
Android Builder mode easy to understand