Gio
Gio

Reputation: 4229

MVC Patterns - controllers and views

When using the MVC pattern, should I implement a seperate controller for each view?

Upvotes: 1

Views: 290

Answers (4)

kyoryu
kyoryu

Reputation: 13065

Create a new one if you need to. Don't if you don't.

Patterns are not about data structures, they're about organizational patterns among communicating components. If the same controller is appropriate for more than one view, great - especially if you can use it without modification.

If you have to change it, then you have a case for two separate controllers. If there is shared code between them, then consider moving it to another class - either a base class or (my personal preference) shared via aggregation.

The easiest way to think about MVC is a command-line program. The program is the Model. The Controller is STDIN. The View is STDOUT.

Upvotes: 1

uray
uray

Reputation: 11572

the idea is to separate/decoupling M, V and C, its not a problem if you want a single controller control multiple view, as long as the view and controller is decoupled

Upvotes: 0

Jonathan
Jonathan

Reputation: 12015

I use to implement a controller for each module of my application, not for each view. A controller can call methods of other controller. I'm not sure if this is the better way to do it, but I think It's working well for me.

Upvotes: 0

koen
koen

Reputation: 13767

I believe there is no 'the' MVC pattern. There are almost as many MVC patterns as there are users of a MVC architecture. That being said, in my opinion, the answer to your question is 'no'.

Upvotes: 0

Related Questions