r/ObjectiveC • • Mar 10 '20

Subclass Factory Pattern

https://whackylabs.com/objc/design-pattern/2020/03/09/objc-builder-pattern/
10 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/whackylabs Mar 10 '20

Yes you're correct in pointing out that what I'm returning is FooBuilder and Foo. But if FooBuilder is a strict subset of Foo, in the sense that there is nothing in FooBuilder that is not in Foo I don't see any harm if someone is able to see the innards.

I see this pattern as more like some implementation details of Foo has been moved to FooBuilder. Since Foo does not implement some methods rather only inherits.

Also, I think Objc is more duck typed language, so if Foo can respond to a selector setTitle: then that is all we care about, we shouldn't care where the actual implementation is.

And like all things, this technique might be good or bad depending on where you wanna use it. I've never used it in a production code so far, so can't tell any pros/cons right now. But I'm using this right now in the app I'm working on to see how I feel about it. I'll probably post an update if I find something not working.