Figure 15.2. Directory structure for the MVC pattern.
This is obviously trivial and might seem like a waste of time to cover, but it is the basis for the structure we will utilize when creating objects we would like to fit into this pattern. Let's take the Accordion component from Chapter 10, "Accordion," as an example. This component is composed of two objects: Accordion and Panel. Figure 15.3 shows the previous MVC structure with the Accordion component and associated model objects.
Figure 15.3. MVC directory structure with the Accordion component.
The Accordion object is the controller for this component because it interacts with another controller (AjaxUpdater) and ultimately the model (Ajax), and responds to the panel with the information from the server. The Panel object represents the view and presents to the user the different panels the accordion is composed of. When a user interacts with a panel, the panel interacts with the AjaxUpdater. This controller then sends a request to the model, which is our Ajax object. Therefore, we end up with multiple MVC triads working together to accomplish a task. Take a look at Figure 15.4 for a graphic view of how the data flows between the objects in this pattern.
Figure 15.4. Graphical view of how the Accordion uses the MVC pattern.
This is a good example of how the pattern can fluctuate. You can use multiple objects from different aspects of the MVC structure to work together as one whole unit, yet keep those objects completely decoupled.