The model

The model of the application consists of the to-do item, the location, and an item manager, which allows the addition and removal of items and is also responsible for managing the items. Therefore, the controller will ask the item manager for the items to present. The item manager will also be responsible for storing the items on the disc.

Beginners often tend to manage the model objects within the controller. Then, the controller has a reference to a collection of items, and the addition and removal of items are directly done by the controller. This is not recommended because if we decide to change the storage of the items (for example, using core data), their addition and removal would have to be changed within the controller. It is difficult to keep an overview of such a class; because of this reason, it is a source of bugs.

It's much easier to have a clear interface between the controller and the model objects because if we need to change how the model objects are managed, the controller can stay the same. We could even replace the complete model layer if we just keep the interface the same. Later in the book, we will see that this decoupling also helps to make testing easier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.138.202