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.

asked Mar 10, 2015 at 13:57
2
  • 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? Commented Mar 10, 2015 at 14:28
  • The communication is based on WebSockets using the socket.io libary with node.js Commented Mar 10, 2015 at 14:42

3 Answers 3

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.

answered Mar 11, 2015 at 12:04
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.

answered Apr 10, 2015 at 17:08
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"
     }]
    }
    
answered Aug 9, 2015 at 20:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.