Polymorphism in Storyboard ViewControllers

瘦欲@ 提交于 2019-12-06 11:12:14

different remote API server calls and CoreData fetches are performed

What you're really calling out here is that the data interface is different than the view interface. That's fine. You should pull out a separate object responsible for fetching data. You can pass that object along to the view controller, rather than polymorphing the view controller. This is called the Strategy pattern, and is very common in Cocoa.

This is almost identical to delegation, which you can also use here. When you segue, the calling view controller sets a delegate on the receiving view controller. That delegate is then responsible for returning the data objects, again freeing the receiving view controller from polymorphing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!