From “Learn XXX in 21 Days” to “Dead Elephant of Java Programming”, almost all introductory programming books will tell you over and over again that “strong clustering, weak coupling”, and I understand that it is very easy to have severe coupling between modules in module partitioning. Your code runs on his code, and then he changes an interface and your code doesn’t run.

So…

  • Modules should be able to be written, run and tested independently
  • Modules need to reduce their dependence on external parameters

If you’re familiar with Web development, you’ll find that the framework needs you to define the Router to make it work. The Router is a request, and it’s up to the module behind the Router to find the corresponding module, render it, and display it. Imagine Web development without any framework, without writing a Router, and a request comes in:



def matchURL(url): if url.find('/article'): Article = article () article. articleId = 1000050 article.title = 'jingle and vases' return article.render() return 'No Match'

With the Router:

urls = (
  '/article/:articleID', 'article'
)

The Router is, in essence, a convention, a rule for passing parameters.

Isn’t it the Router that solves the problems we encounter? Each other does not need to care about what the other module does. When it needs to call the other module, just like the Router, it does not need to care about what the other module does and what interface it exposes. In this way, the root is unconnected.

In fact, as early as in ancient Three20 era have used this kind of thought made the wheels of the: https://github.com/alunny/three20/blob/master/src/TTNavigator.m

Then the more recent editions are: https://github.com/gaosboy/urlmanager https://github.com/Huohua/HHRouter https://github.com/usepropeller/routable-ios https://github.com/aaronbrethorst/ABRouter

The Router registers the URL and corresponding Controller, and then forgets the creation and initialization of the Controller, and asks the Router directly for:

/ / registered [[HHRouter Shared] map: @ "/ read / : userId/" toControllerClass: ReadController. Class]; // call [[HHRouter shared] matchController:@"/read/1/? TabIndex =3"]

With this idea, the coupling between modules is reduced because the parameters are passed to each other via URLs, and the Controller is clearer.

Reference: http://pizi.me/86 https://github.com/gaosboy/urlmanager/