I did find some suggestions for this topic but still there are some things left open for me.
The question is about designing an app (from a development point of view) especially concerning models.
For example, I’m building an app with the Facebook SDK. I guess it would make sense to have a model class for the communication with the Facebook API. And i guess it would make sense to make this class a singleton (doesn’t have to be).
But the Facebook SDK for iOS builds on delegates. So you send a request and the response returns in a delegate method in the model. That’s okay, but I also would like to assign a delegate to the model so that the view controller is then called.
So, for example, a view controller uses the Facebook-singleton-model to make a request but wants to set itself as a delegate for this request, so that the model calls this delegate when the request is finished.
But this model is a singleton it only has one delegate (and i want it to keep it like this).
So do i overwrite the delegate pointer in the Facebook-singleton before each call? (No good, because another request might start in the meantime using the same singleton and the delegate would be overwritten again).
So what is a good architecture? What are best practices for reusing models across an application?
I ended up using singletons for my models which works really well with the following thread-safe code of getting a sharedInstance (the singleton)
Working great is also the usage of Key-Value-Observing (KVO) in iOS. I can watch for changes on properties in the model and react in the view-controller. IMO this allows to create very clean and understandable code. (look it up and love it at: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/KeyValueObserving/KeyValueObserving.html)
On one point I’m also using a Model and set it up as a delegate and gave it a set of delegates which than broadcasts the delegation methods to all observers, which i find is also kind of nice.