-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should XExtensionItemMutableParameters be replaced with a builder class? #1
Comments
I'd prefer a builder over that monster of an initializer any day |
❤️ @robb |
Me too, but I prefer mutable subclasses ever so slightly to builders. |
Objective-C initializers are basically factory methods anyway (since they can return any object or even nil), so an |
@mattbischoff Mutable subclasses and monstrous initializers go hand in hand. You need the latter in order for the former to be of any use. |
I'm personally a +1 for using builders. I wonder if it might be an acceptable compromise to offer a builder, but not deprecate the mega-initializer. People who are that scared of using a builder can just use the nasty verbose initializer. |
I guess this is not technically true. The mutable subclass could be defined in the same file as the immutable base class, and the monstrous initializer would be made internal to the |
Are there any default parameters? |
No |
Unrelated to this one, but I've used a builder for requests before and enjoyed being able to have format strings along the way, e.g.: [[[[XYRequestBuilder
GET:@"/users/%@/", userID]
params:@{ @"foo": @"bar" }]
whatever:&amen]
build]; |
I feel like a big part of why some iOS developers don't seem to be fans of builders is that they assume that most of the value comes from the method call chaining commonly associated with the pattern, which generally looks aesthetically terrible in Objective-C. I've made plenty of Objective-C builder classes that don't expose a fluent interface yet still provide all of the other benefits of separating out object construction. |
I think keeping the mutable subclass around but providing a convenience initializer that takes a block with an - (instancetype)initWithBlock:(void (^)(XExtensionItemMutableParameters *mutableParameters))configurationBlock; |
Agreed. Great solution. |
Bunch of cleanup work on top of Ari’s `XExtensionItemSource` refactor
Mutability should be avoided. A great way to provide an easy-to-use object creation API is by using the builder pattern.
Unfortunately, many Objective-C developers seem adverse to using builders. As such, the first version of this library includes the
XExtensionItemMutableParameters
subclass, which allows one to create anXExtensionItemParameters
instance without using its initializer (which takes a large number of arguments).I'd prefer a builder but want this library to be as approachable as possible. The introduction of a builder class means
XExtensionItemMutableParameters
would be deleted altogether, andXExtensionItemParameters
's large initializer would be made private. The only way to get an instance would be to use the builder object and then callbuild
at the end.The text was updated successfully, but these errors were encountered: