For an example of embedded presentation logic, we can take a look at Appendix E, Code before Collecting.
Presentation Logic. The code shows a page script that has been refactored to use domain Transactions, but it still has some presentation logic entangled within the rest of the code.
Note
What Is The Difference Between Presentation and Business Logic?
For our purposes, presentation logic includes any and all code that generates output sent to the user (such as a browser or mobile client). This includes not only echo
and print
but also header()
and setcookie()
. Each of these generates some form of output. "Business logic," on the other hand, is everything else.
The key to decoupling the presentation logic from the business logic is to put the code for them into separate scopes. The script should first perform all of the business logic, then pass the results over to the presentation logic. When that is complete, we will be able to test our presentation logic separately...