|
-
Mar 7th, 2006, 11:07 AM
#3
Re: If you were sent this as part of a job application what would you do?
It means that applications should be separated into at least to distinct parts (I like to call them layers).
The Processing Layer - this should receive any input, make database connections, execute queries. In short (it is responsible for the retrieval and manipulation of data from one format to another). This layer should never produce any output or display specific data (such as HTML code).
The Output Layer - this receives the processed data from the processing layer and displays it. At the simplest level in OOP, your output layer would be a class called Template with a single method called display(), which when called with the path of a PHP file, includes it like a template an produces output. The output layer deals solely with the display of data; it should never be changed or manipulated here and anything like database interaction, file manipulation and processing of form input is a big no no.
Why do this? Because it makes refactoring your application easier. So when your boss approaches you and says (our MSSql license is running out, therefore we are moving to MySql), you won't poo your pants and run a mile. Ideally you would have exercised even more fore sight and created a database abstraction layer in you processing layer, making the change as simple as changing a few lines of code.
It also means redesigning the look of a site is a lot easier, you won't have to dig around inside files littered with PHP code. Sure, the templates can, and in many cases need to contain code, however, this should be limited to conditionals and loops. PHP even provides alternate syntax for this:
PHP Code:
<?php if (condition): ?>
<html>
<?php elseif (condition): ?>
<html>
<?php endif; ?>
The same goes for, while, for and foreach loops. Have a peek at the article about PHP 5 OOP for a few tips and design patterns in OOP, even if you just use PHP 4, it is still helpful to read.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|