vendredi 11 décembre 2015

obj-c pattern to separate model and network-layer

I am trying to improve the design of my applications model initialization and update.

What I have

Currently I have a more or less MVC structure with the model classes having most of the variables readonly and these can only be updated by sync'zing the app with a server: a json file will be received and a dictionary passed to a predisposed model class method

[ModelClass updatewithDictionary:(NSDictionary*)jsonDictionary] 

but this way all the json keywords and structure, that i believed should be kept wrapped inside the network-layer of my app, have to be handled by the Model.

An alternative

One alternative solution is to let the Model be read/write and have a Factory/initializer/whatever class which instantiate or update them. This would cause unfortunately to expose the should-be-private members of my model classes.

What I am looking for

Is there a Pattern which would impose separation of model from it's instantiation letting information-hiding principle survive and without using proxy-classes (or whatever java-like class-explosion-generating method)? A somewhat friend principle in c++.

Aucun commentaire:

Enregistrer un commentaire