Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase layer design
    primarykey
    data
    text
    <p>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.</p> <p>Following operations that can be done on Customer,</p> <ul> <li>Adding a Customer</li> <li>Editing Customer details</li> <li>Delete Customer</li> </ul> <p>So I thought of including a Class named 'CustomerManager', included following methods, </p> <pre><code> @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 </code></pre> <p>In the ViewController where ever I need to perform customer related operations, I used to make it like this,</p> <pre><code> Customer * manager = [Customer sharedManager]; [manager addCustomer:customer]; //fetch customer [manager customers]; //While deleting [manager deleteCustomer:customer]; </code></pre> <p>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.</p> <pre><code> @interface Customer + (BOOL)addCustomer:(Customer *)customer; + (BOOL)deleteCustomer:(Customer *)customer; + (BOOL)updateCustomer:(Customer *)customer; + (NSArray *)customers; @end </code></pre> <p>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.</p> <p>Which was the best way?. I would like to have some detailed answer for this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload