I am not new in the programming world, however I need help with understanding what is going on in this code. I DO understand the builder pattern and the Action delagete (does not return anything, but can take some parameters).
What bothers me a lot is below code:
0. var carBuilder = new CarBuilder().WithDoors(x => x.WithDoors(4)).Build();
1. public CarBuilder WithDoors(Action<DoorsBuilder> x)
2. {
3. var doorsBuilder = new DoorsBuilder();
4. x(doorsBuilder);
5. _car.AddDoors(doorsBuilder.Build());
6. return this;
7. }
- What happens in line 4?
- What do I actually pass in line 0 to WithDoors function?
- Is is possible to rewrite that code in some simpler way (to get better understanding :))?
Code: https://rextester.com/SIOV54215
Aucun commentaire:
Enregistrer un commentaire