I have design level question in one of my project.I'm working on a project in which I need to fetch some objects using REST. Say for example fetch Customers and show it in a list.
Following operations that can be done on Customer,
So I thought of including a Class named 'CustomerManager', included following methods,
@interface CustomerManager
- (CustomerManager *)sharedManager;
- (BOOL)addCustomer:(Customer *)customer;
- (BOOL)deleteCustomer:(Customer *)customer;
- (BOOL)updateCustomer:(Customer *)customer;
@end
@implementation CustomerManager
- (BOOL)addCustomer:(Customer *)customer;
{
NetworkManager * manager = [NetworkManager manager] addCustomer:customer ];
}
@end
In the ViewController where ever I need to perform customer related operations, I used to make it like this,
Customer * manager = [Customer sharedManager];
[manager addCustomer:customer];
//fetch customer
[manager customers];
//While deleting
[manager deleteCustomer:customer];
Everything is looking and working fine, until I get a design level question, why there was a manager in-between . All the work was done on Customer Object, so you need to have all the Customer related operations in the Customer Class, like something below.
@interface Customer
+ (BOOL)addCustomer:(Customer *)customer;
+ (BOOL)deleteCustomer:(Customer *)customer;
+ (BOOL)updateCustomer:(Customer *)customer;
+ (NSArray *)customers;
@end
The problem here is , even though network related code in a separate class, I need to have a Concrete reference of my network manager in all my model classes. Confused , which one to choose.
Which was the best way?. I would like to have some detailed answer for this.
I don't believe there to be a correct answer here. I personally have gone back and forth on how to have my web services interact with my models. But I can provide you with a few pointers: