Remember about default values, which is a thing in C# and Kotlin. Sorry, Java.
Also you can place these setters inside original Burger class. Unfortunately, this way object initialization wouldn't be atomic anymore.
I just checked google, so I wouldn't suggest using double braces initialization for Java. C# initializers are OK, though, and atomic. I do not know of the same stuff for Kotlin, but its syntax for constructors is great in the first place.
Basically, the problem grows out of Java itself, because I see more elegant solutions in other languages like C# and Kotlin. At least more complex example required in order to favour builders and factories.
If you don't need your properties to be necessarily set at creation, you can also set properties when constructing the object in C# even if they're not in the constructor.
var burger = new Burger(14){ Cheese = true, Tomato = true, Lettuce = false, Pepperoni = false };
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for the article.
I want to add couple-o-things. I'm sorry if I sound pushy, please feel free to parry my notes and point my mistakes.
Please, oh please, do use named arguments for vague stuff (concerning methods as well):
Remember about default values, which is a thing in C# and Kotlin. Sorry, Java.
Also you can place these setters inside original Burger class. Unfortunately, this way object initialization wouldn't be atomic anymore.
I just checked google, so I wouldn't suggest using double braces initialization for Java. C# initializers are OK, though, and atomic. I do not know of the same stuff for Kotlin, but its syntax for constructors is great in the first place.
Basically, the problem grows out of Java itself, because I see more elegant solutions in other languages like C# and Kotlin. At least more complex example required in order to favour builders and factories.
True that. It'd be much easier if there was a concept like named argument in languages like Java.
If you don't need your properties to be necessarily set at creation, you can also set properties when constructing the object in C# even if they're not in the constructor.