Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Background

So I have a REST API that allows for client applications to access and manipulate users' data.

I'm in the process of writing an Objective-C class for simple utilization of this REST API, but I'm stuck between two methods of implementation.

Method 1

class MYClient
    string username
    string password
    methods for using GET, PUT, POST, DELETE on questions
    // questions are dictionaries with 'title' and 'body' strings

Method 2

class MYUser
    string username
    string password
    array  tokens
class MYToken
    string title
    string body

// classes inherently sync themselves to the server in their initializers, setters, and getters

Questions

  • Is there one that is more appropriate for use in (for example) iOS apps?
  • Is there one that is more appropriate in general?
  • What are the distinct benefits of Method 1 over Method 2 and vice versa?
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The difference is going to be the number and granularity of HTTP requests that go over the network.

Method 1 is going to send fewer, larger requests that perform operations on a batch operations. Method 2 is going to send more, smaller requests every time an object's property is modified.

Method 1 is also going to give you the ability to queue up a bunch of changes client-side then give the user the option to cancel or commit the changes. Method 2 is going to commit each change individually and immediately. If the user cancels or undoes an operation then a second request will be needed to undo the changes server side.

Based purely on their own merits, I prefer Method 1. However, which one is more appropriate for your app depends on the functionality you are looking for.

UPDATE: In Method 1, MyClient.DoSomething() does not have to "do something" to one object at a time. Say you want to create 5 new MyUser objects. You don't have to call MyClient.Create(newMyUser) 5 times, once for each new MyUser object. Your Create() method can take an array of objects and all 5 new MyUser objects can be sent to the server in the body of a single POST. Similarly, say you want to update the UserName and Password properties on the same MyUser object. Method 2 would result in 2 requests, each sending a copy of the whole MyUser object for each property change. Method 1 would allow you to make the changes to both properties client side then send the MyUser object with both property changes to the server in a single PUT. In both scenarios, Method 1 gives you the option to delay pushing changes to the server until you call the appropriate method in MyClient and pass in the changed objects. In Method 2, changes to each object are pushed to the server immediately and individually.

share|improve this answer
    
Any chance you could expound on the queueing concepts, as this is not something that I'm entirely aware of / was considering :) –  pcperini Feb 16 '12 at 18:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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