c# - REST - Good design practice -
i new in windows phone development , trying write app retrieves data server , displays them user. have several resources on server, lets user, quest , activity. use restsharp lib retrieve data server.
example of user:
public void get(string id, lifehunt.mainpage.userready userready) { var client = new restclient(deployd.rest_url); var request = new restrequest(resource + "/{id}", method.get); request.addurlsegment("id", id); client.executeasync<user>(request, response => { if (response.statuscode == system.net.httpstatuscode.ok) { userready(callback.data); } }); }
once user retrieved, call userready method passed callback , user mainpage display it.
now, have repeat whole process crud (insert, get, getall, update, delete) functions users, quest , activity. means need 15 different callback methods, think not software design.
the other way 1 callback method , check type of parameter passed in callback method. not think nice solution well.
i thinking creating generic interface crud, implement user, quest , activity classes:
interface icrud<t> { void getall(genericcallback callback); void get(genericcallback callback); void add(t item, genericcallback callback); void remove(string id, genericcallback callback); void update(t item, genericcallback callback); }
however not know how implement , if way. suggest me design solution?
use mvvm, create viewmodel hold data need , bind view. create service class methods directly returning data need (no callbacks). create instance of service in viewmodel , call methods , fill data when needed.
Comments
Post a Comment