I am currently working on a project where I want to be able to create a options object by dynamically setting its properties on creation.
This made me come up with this type of constructor-setter combination:
Options options = new Options()
.fontSize(12)
.color(Color.RED)
.showLabels(false);
Which would be equivalent to the less sleek looking:
Options options = new Options();
options.setFontSize(12)
options.setColor(Color.RED)
options.setLabelVisibility(false);
I have already seen something similar in Spring where you sometimes configure settings like this:
protected void configure(final HttpSecurity http) {
http
.antMatchers("/auth/admin/*").hasRole("ADMIN")
.antMatchers("/auth/*").hasAnyRole("ADMIN","USER");
}
This made me wonder wether it is something that is commonly used and perhaps is some kind of design principle that has a name. Is this the case?