MVC- the king of design patterns
Model View Controller is a Cocoa one of the cornerstones, and undoubtedly the most commonly used design pattern in all design patterns, it classifies objects according to the general character in your application, encouraging the separation of roles in a completely detached mode.
Model: This object Hold your application data and define how to manipulate it, for example in this case the Album class.
view: This object is in charge of model visual display, and control of user interaction, basically all is uiview and its subclasses. In this case, this is the separated albumview class.
Controller: controllers are regulators that regulate all work, access the data in the model, and then display it in a view, listening to events and manipulating data as required. Can you imagine a Controller in this one , or viewcontroller ?
scenarios where views and models are communicated through a controller can be described as:
650) this.width=650; "Src=" http://img.blog.csdn.net/20140724122302644?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvc2fuanvuc2hlbmc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "/>
if theModelIf there is any data change in it, it will notifyController,in turn,ControllerUpdate inViewin the data,Viewcan notifyControllerabout the behavior of the user, and thenControllerupdate the data as needed or retrieve the requestedModel.
you might wonder why not just create a Controller then the View and the Model and put it in there to achieve it? Doesn't that look much easier?
All this is for code separation and improved reusability. Ideally, the view should be from the model model model to show some other data to make it reusable.
For example: If you want to add some movies and books to your library in the future, you can still use the same Albumview to show the objects of your movies and books, and further, if you want to create a project to deal with the album, you can easily reuse your Album class, because it does not depend on any one view. This is the magic of MVC.
How to achieveMVCMode
First of all, you need to make sure that every class in your project is a controller, or view, or model, do not speak of any two roles in the task connected together, by creating album and ALBUMV classes you have done a good job.
Second, in order to ensure adherence to this working method, you should create three engineering groups to hold your code, one for each type of grouping.
Press and hold the Command+option+n key to create a group named model, create view and controller, drag Album.h and ALBUM.M into model, drag AlbumView.h and ALBUMVIEW.M View group, and finally drag ViewController.h and viewcontroller.m to the controller group.
At this point your engineering structure should look like this:
650) this.width=650; "Src=" http://img.blog.csdn.net/20140724122635257?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvc2fuanvuc2hlbmc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "/>
Now it doesn't look like those papers are floating around for four weeks, looking much better. Obviously you can have other groups and classes, but the core of this application is contained in these three classes.
Now that your components are organized and you need to get album data from somewhere else, you will create an API class to manage the data in all of your code-this will be shown in your next design pattern, the singleton.
MVC-The King of design patterns