0

Actually I'm going to build an Client Server Application, at the Login I recive the User Object from the Server. An user has a List of tasks, but I don't want to load them at the Login. So what would be an good style to recive the Tasks of an user. Should my user have an "GetTasks()" function which will access the server and will return the Tasks, which would be an strongly object orientated method. Or should I Use an Service, which has a function that takes the user as parameter and returns the task.

  • what kind of client server application are you developing? Is the client web browser and the server an HTTP server? or are you using TCP based custom networking? or is it RMI? – Jit B Mar 10 '15 at 14:28
  • The communication is based on WebSockets using the socket.io libary with node.js – Ced Mar 10 '15 at 14:42
1

Should my user have an "GetTasks()" function which will access the server and will return the Tasks, which would be an strongly object orientated method.

I am not sure it's something strongly object-oriented.

Or should I Use an Service, which has a function that takes the user as parameter and returns the task.

Of course it would be better to use Service for that. Follow SoC here.

0

How about decoupling the user model from the task model. Instead create a TaskManager object that could get the tasks for the user. Something like

TaskManager.getUserTasks(user); //which would return a list of Task objects

the advantage of keeping these two is that you can keep on adding functionality without having to change the User model.

0

It is not quite clear, what you want.

at the Login I recive the User Object from the Server

An user has a List of tasks, but I don't want to load them at the Login

So what would be an good style to recive the Tasks of an user

If I understand that correctly, the list of tasks could be long, so receving the list of task would be something which has a negative impact on the time it takes to log in; so you want to decouple that?

Then the first question is, why you are retrieving a whole user object at all? A slimmed down model would do.

Should my user have an "GetTasks()" function which will access the server and will return the Tasks, which would be an strongly object orientated method. Or should I Use an Service, which has a function that takes the user as parameter and returns the task.

Without code and your poor description it is hard to guess, what you are doing at all.

You should distinguish between

  • Frontend

    If you have a "model" (e.g. a Backbone-Model), which represents a user, then a "method" getTasks() makes perfect sense

  • Backend

    On the serverside, a Service is needed to retrieve the tasks. I suggest building a REST ful service where you would have an URI like api/users/{id}/tasks which would return a list of tasks for a user with a given id (which is given as a "path"-variable {id}):

    {
      "tasks": [{
        "name": "task1",
        "description": "Doingstuff",
        "links": [{
          "rel": "self",
          "href": "http: //localhost: 8080/api/users/1/tasks/1"
        }]
      }],
      "links": [{
        "rel": "self",
        "href": "http: //localhost: 8080/api/users/1/tasks"
      }, {
        "rel": "user",
        "href": "http: //localhost: 8080/api/users/1"
      }]
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.