In “Pattern Oriented Software Architecture – Vol 1” (p. 131), the author said that View
is responsible for creating Controller
. But in “Head First Design Patterns” (p. 562) it is the Controller
that creates the View
. In some other references I see that nor View
niether Controller
create each other. Only Controller
has a reference of View
and/or vice versa.
What’s your opinion about this? Does this depend?
1
Well, I can only assume this changes along different platforms.
On the android library, you create the view from the controller.
i.e., in your Activity
you call setContentView...
to “awake” you XML (The view) and create it.
On the other hand, in the iOS world, you would ask the View (storyboard
or .xib
file) to awake (Actually you ask the system to go to the app’s bundle, get the View and create it) itself up, than it will awake your controller (e.g., myView
) and awakeFromNib
will be called…
I might not be precise about the small details, but you can see that different platforms would create this connection in slightly different ways, depends on the architecture.
Does it really matter what creates what though? It depends imo, as long as business logic and view are separated it’s alright. Controller should have a reference to both of them and provide means to translate data from the logic to the view and vice versa. But honestly, in real world applications, no matter how hard you try you will put some of the logic inside of the controller too.
1