vendredi 15 avril 2016

Design Pattern HTTP Api

I'm building an app that is based on data provided by an REST api. I use the alamofire framework to request the data from the api. At the moment everything works but it's kind a messed up in a lot of ways, so I want to structure it and use some design patterns to have more control over my code.

I created some entity classes that are basicly my data layer. The data layer should be up to date everytime I use these objects. Data updates / api connections could be triggered by timeintervals or by user action (if he edits some data and saves it or sth like this).

After that my UI should always update if data has changed and if that viewcontroller is active.

The problem is that the request and the receiving of data is asynchronous and I don't know a good way to structure everything.

At the moment the request to the api is always triggered by the viewcontroller. After data is received I call some methods in the viewcontroller itself via delegation and update the ui. It's kind a messy with all the different requests and different data that is send to api. I need to generalise everything and clean it up. And one of the problems at the moment is, that one viewcontroller can only handle one kind of request. For example, the viewcontroller can only save an edited post, but can not receive a post, because the same method would be called after receiving data.

So, does anyone know how it is done correctly and in a very structured way? Maybe some ideas or designpatterns or how one of the big players handle such problems.

Aucun commentaire:

Enregistrer un commentaire