Lines 37 - 44: A helper method for encoding strings for transmission across the web.

Lines 46 - 63: This code is very similar to the original ContentBroker code. Specifically, as a URL is loaded, the data is saved in a property named contentData. Once it completes, or if an error is encountered, a callback method is invoked.

Lines 62, 67 - 69: When the data has been loaded, the method parseContents is invoked. The base implementation of this method logs an error. This is because each concrete class that subclasses this class must specify how the data will be parsed. (In the Android implementation, parseContents() is abstract.)

Lines 71 - 79, 12, 22, 31: Two additional "abstract" methods. They should be implemented in the concrete subclass so that the methods loadContentFromServer and postContent are able to get concrete class dependent URLs and content.

LocationService

#import <Foundation/Foundation.h>

#import "FishingSpot.h"

#import "ContentBrokerDelegate.h"

@protocol LocationService <NSObject>

-(BOOL) create:(FishingSpot *)x error:(NSError **)error;

-(BOOL) update:(FishingSpot *)x error:(NSError **)error;

-(BOOL)delete:(FishingSpot *)x error:(NSError **)error;

-(BOOL) get:(long)x error:(NSError **)error;

-(BOOL) getMany:(NSString *)criteria error:(NSError **)error;

-(void) setDelegate:(id<ContentBrokerDelegate>) delegate;

@end

Comments:
This protocol is very similar to the other service protocols, such as CatchService, and FishService. Each protocol focuses on a specific business object, and exposes basic CRUD operations to the application. The only other item of note is the setDelegate method: This provides a callback object that will be notified when the various operations complete.

Lines 13 - 25: The web-based implementation for creating a new FishingSpot. This is very similar to the LocationBroker code that was previously used.

Lines 27 - 39: Update a FishingSpot on the server.

Lines 41 - 67: The implementation for deleting and retrieving FishingSpot objects. The key point is to set the proper action and URL, and then invoke loadContentFromServer. (As you will recall, this method is implemented in the parent class - AbstractServiceWeb)

Lines 73 - 144: Once the response from the server has been retrieved, this method is responsible for decoding the response, and then notifying the delegate. The method retrieves basic return code information, and then parses any FishingSpot objects that are available.

Now that the two classes and the protocol have been described, it's time to create the ServiceFactory class, and then update the app to use this service instead of the LocationBroker class.