[Question] - Builder versus configuration object
See original GitHub issueQuestion as to why you used the builder pattern instead of a configuration object pattern for configuring instances.
The following has ten total method calls just for one button.
var CustomButton = new MKButton.Builder()
.withBackgroundColor(MKColor.Teal)
.withShadowRadius(2)
.withShadowOffset({width:0, height:2})
.withShadowOpacity(.7)
.withShadowColor('black')
.withOnPress(() => {
console.log('hi, raised button!');
})
.withTextStyle({
color: 'white',
fontWeight: 'bold',
})
.withText('RAISED BUTTON')
.build();
The MooTools configuration pattern uses just one
var CustomButton = new MKButton({
backgroundColor : MKColor.Teal,
shadow : {
radius : 2,
opacity : .7,
color : 'black',
offset : {
width : 0,
height : 2
}
},
textStyle {
color : 'white',
fontWeight : 'bold'
},
onPress : () => {
console.log('onPress')
}
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Builder pattern vs. config object - java - Stack Overflow
The builder pattern improves decoupling - your Product can be an interface and the only class that knows about the implementation (or ...
Read more >Interact overview - Tanium Documentation
A dynamic question is one that you create and issue through the Ask a Question or Question Builder features in Interact. A saved...
Read more >Builder - Refactoring.Guru
Builder is a creational design pattern that lets you construct complex objects step by step. The pattern allows you to produce different types...
Read more >Articles Key Questions Overview
Key Questions are configured using the App Config Builder button, ... Key Questions displays all fields from the Application object.
Read more >Create a question for a catalog item in catalog builder
The fields on the form vary based on the question type and subtype. · While you configure each question,its preview is available. ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @jaygarcia, thanks for the valuable question.
The same question has been frustrating me 😖, until I realize that I’m not going to obsolete the object pattern by introducing builder. I just can’t, configuration object is built into the heart of ES7 (Object Spread) and thus React (Props Transferring). For example, you’re always free to do this:
the props objects can be reused & extended:
So, my reasoning is that
the builder
is just another way to make and reuse view definitions, hoping those who feel familiar to builder pattern or method chaining will like it.An additional reason to introduce
builder pattern
is that it can make the best out of IDE’s code completion feature (e.g. WebStorm).It is not an either-or situation, you can even mix them up, to leverage the pre-defined theme:
Hope my choice is reasonable, 🍻. I’ll leave this issue open in case of someone interested wanna join the discussion.
It would be great to able to combine the approaches. So use the builder pattern to configure widgets that you will use then be able to customise them at runtime using props. I know you can do this with some props but not all.
Specifically Text doesn’t work, I’m not sure about other props yet.