PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 12 ■ ENTERPRISE PATTERNS




As you can see, the feedback message set in by the default command has found its way into the
output. Let’s review the full process that leads to this outcome.


Overview


It is possible that the detail of the classes covered in this section might disguise the simplicity of the
Front Controller pattern. Figure 12–5 shows a sequence diagram that illustrates the life cycle of a
request.
As you can see, the front controller delegates initialization to the ApplicationHelper object (which
uses caching to short-circuit any expensive setup). The Controller then acquires a Command object from
the CommandResolver object. Finally, it invokes Command::execute() to kick off the application logic.
In this implementation of the pattern, the Command itself is responsible for delegating to the view
layer. You can see a refinement of this in the next section.


Figure 12–5. The front controller in operation


Consequences


Front Controller is not for the fainthearted. It does require a lot of up-front development before you
begin to see benefits. This is a serious drawback if your project requires fast turnaround or if it is small
enough that the Front Controller framework would weigh in heavier than the rest of the system.

Free download pdf