r/ObjectiveC • u/whackylabs • Mar 10 '20
Subclass Factory Pattern
https://whackylabs.com/objc/design-pattern/2020/03/09/objc-builder-pattern/
10
Upvotes
r/ObjectiveC • u/whackylabs • Mar 10 '20
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
FooBuilderandFoo. But ifFooBuilderis a strict subset ofFoo, in the sense that there is nothing inFooBuilderthat is not inFooI don't see any harm if someone is able to see the innards.I see this pattern as more like some implementation details of
Foohas been moved toFooBuilder. SinceFoodoes not implement some methods rather only inherits.Also, I think Objc is more duck typed language, so if
Foocan respond to a selectorsetTitle: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.