I have a question about the level of design in one of my projects. I am working on a project in which I need to get some objects using REST. Say, for example, customer samples and their display in the list.
The following operations that can be performed on the client are:
- Add customer
- Editing customer information
- Delete customer
So I was thinking of including a class called "CustomerManager" that includes the 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 operations related to the client, I did it like this,
Customer * manager = [Customer sharedManager]; [manager addCustomer:customer]; //fetch customer [manager customers]; //While deleting [manager deleteCustomer:customer];
Everything looks and works fine until I get a question at the design level why there was a manager between them. All the work was done on the Customer object, so you need to have all the operations related to the Client in the client class, for example, something below.
@interface Customer + (BOOL)addCustomer:(Customer *)customer; + (BOOL)deleteCustomer:(Customer *)customer; + (BOOL)updateCustomer:(Customer *)customer; + (NSArray *)customers; @end
The problem is that although the network code is in a separate class, I need to have a specific link from my network manager in all my model classes. Confused which one to choose.
What was the best way ?. I would like a detailed answer for this.
source share