6

I am referring to the general MVC design pattern (as defined in Wikipedia). When doing a GUI-intensive application, I would generally have many controllers, and sometimes a controller could send an event to another controller.

Does MVC in general defines how controller should communicate with controller? Could a controller be the model for a controller higher up in the hierarchy?

Example Suppose I have a window (which is represented by a controller/model/view), and that window is capable of launching another sub-window. The sub-window is modal, and will accept certain input. The input will affect certain processes in the main window.

Kris
  • 2,100
  • 5
  • 31
  • 50
Extrakun
  • 19,057
  • 21
  • 82
  • 129
  • Why would your controller need to communicate with another controller? – Christian Wattengård Nov 25 '11 at 09:38
  • Can you give an example of when you might want to use a controller to communicate to another controller? You probably just communicate with a model the controllers just handle the request. – PeeHaa Nov 25 '11 at 09:38
  • Example added as per requested. – Extrakun Nov 25 '11 at 10:16
  • 1
    In addition to the patterns suggested by jgauffin, also take a look at the delegate pattern. Apple heavily relies on this pattern to accomplish what you want, where the higher level controller functions as delegate for the lower lever controller. – eelco Nov 25 '11 at 11:18

3 Answers3

2

No. You can not do that with MVC. You want to use some kind of hierarchical pattern like one of the following two:

Community
  • 1
  • 1
jgauffin
  • 99,844
  • 45
  • 235
  • 372
0

Referring to Wiki Model–View–Controller (MVC) is an architecture that separates the representation of information from the user's interaction with it.

With that said it don't define any event mechanism, so there is no specification for intra controller communication.

Now coming to your question.

you can have view rendered from one controller and submit data to another controller. that should just work fine.

define form with <form action = "parentcontroller/parentaction"> to make it happens.

bijayk
  • 556
  • 3
  • 18
0

No a controller can not be a model for another controller. Controllers just can pass arguments through Get or Post

Manoochehr Dadashi
  • 715
  • 1
  • 10
  • 28