Understanding the MVC Design Pattern in Cocoa Touch

Usually I just build the application in any random way if it works, but that means that I don't pay attention to any design patterns. Currently, my application makes extensive use of global variables (I transfer an instance of mine AppDelegateto each view controller to access the properties declared in mine AppDelegate.h). Although he does what I want to do, I read that this is not a good design practice.

So, I want to start making my code "legal". However, I cannot imagine my application right now without global variables. They are so important for the well-being of the application, but that should mean that I am doing something wrong, right? I just can’t imagine how else I will do something. Take for example the following:

enter image description here

You have two view controllers: SideViewControllerand a MainViewController. Using global variables, such as, for example, if the entire application was a general entity SideViewControllerand MainViewController( appDelegate.sideViewControllerand appDelegate.mainViewController) I can easily exchange data between the two view controllers, so that when you click the "News" Feed "in my SideViewController, I can tell my MainViewControllerto restart his.

, , ? SideViewController, MainViewController , ?

+5
1

, , ? SideViewController , MainViewController , ?

, , SideViewController MainViewController .

? , :

  • . , , MainViewController SideViewController.

  • , , .

MainViewController SideViewController, . , SideViewController. , MainViewController SideViewController ( MainViewController), SideViewController MainViewController.

- ( - ) MainViewController, SideViewController, ​​ .

, , , -, .

, , , , , - . , , :

  • . SideViewController delegate , , SideViewController . MainViewController. MainViewController SideViewController. SideViewController , , - , . SideViewController -, MainViewController, .

  • : SideViewController - , . , -, SideViewController, , SideViewController, .

  • MVC: , MainViewController, - , SideViewController . , MainViewController ( , ), .

, Erik Buck Cocoa Design Patterns, . , , . , ( ) .

+5

All Articles