Doubts structure of a crud on Android

Asked

Viewed 54 times

0

I have the following classes: Client, Clientedao and DAO.

In the Client template I have attributes and gets/sets.

In Clientthe I have the methods save(), change(), ... ie the crud. This class assembles a string with the parameters and sends to the DAO.

In DAO it is a class that has the methods of the Volley library that makes the connections to the web service. After sending it receives a JSON as a response and sends it to the Clientedao that treats this JSON by transforming it into an object using the Gson library and then returns the object to the class you requested.

The DAO class is a class that is used by all classes that require a connection to webserver.

Is this logic correct? Because I can think of the following problem:

Suppose I make a call to the Clientclass that your return will include the user name in a Textview. It turns out that the application will be locked until it gets that return.

How can I fix this?

Thank you.

  • Application will not be "locked", requests http, can no longer be done in the thread main... You can put a text in Textview from Carrying, or create a progressDialog, to inform that it is going to fetch the data..

  • Thanks for the comment! So the structure I created is correct?

  • Just a detail, the DAO Pattern is a standard for database, I just found it strange the DAO class to access the webservice.. maybe you’ll get a little confused,

  • How would you do?

  • 1

    Abandon this pattern to mess with webservice. Creates a class (class x) that has the crud methods and these methods receive the object per parameter. Then Voce creates an asynctask, which is when Voce runs some task in the background.... Inside the asynctask Voce program for the class x request in the webservice... In Activity, Voce calls the async task that she will order the webservice in the background. so the application will not get stuck...

  • I would simplify things as @Mr_anderson said. Create simple objects (POJO - Plain old java Objects) and use a REST library that automates the call and deserialization of json, such as Retrofit (http://square.github.io/retrofit/), my favorite, or spring (https://springio/guides/gs/consuming-rest-android/). With retrofit you don’t even need to create a class to be your "DAO", in this case your "Client Rest", because it already creates for you. All you have to do is consume the code

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.