Hi everyone,
Apologies for letting the thread idle for a while, things have been extremely busy.
After building a few projects in OOPHP I've come to a basic understanding of how it all works together.
I've made some REALLY big mistakes and yes, as much as I regret to admit it - if anyone who is well versed in PHP takes a look at the first application that I've built using OOPHP the words "what a hack" would escape their lips.
So the first project developed was as expected. I developed an application using a structural decomposition with classes like:
"FormWriter" - which encompasses all form HTML
PHP Code:
$formWriter = &new FormWriter();
"FormElements" - abstracts HTML for form elements either composed or aggregated by formWriter class.
PHP Code:
$formElements = &new FormElements();
$formElements->setText("fieldName","text","this is going to be a nightmare");
"FormProcessor" - which encompasses all form processing for the application
PHP Code:
$formWriter = &new FormProcessor($_REQUEST);
As one can imagine, the classes were bloated. for each form that was created, there had to be a method in both formwriter and formprocessor classes.
I decided to add a new function and it was so convoluted that parts of the application stopped working.
Adding an extra field to a form meant that I had to look at the two super classes for the specific methods and make changes there - expected thrashing was experienced. It was hella painful.
Anyway... here's a summarised solution for the initial problem:
- Request Class - collates $_GET and $_POST variables and cleans them up for use.
- Email Class
// modified classes from harry fuecks book.
- MySQL Abstraction class
- MySQL Query class
- User Class - properties consist of details including access levels and personal details
- UserDao extends MySQL - is composed by user class
- Jobs Class - has the details for each job as a property and a list in text or HTML format.
- JobsAdmin extends Jobs - has additional display options for administrators
- Jobs Dao extends MySQL - is composed by jobs class
I've avoided using template classes and the like and used include files for the front end.
I'm still at a stage where I am using a page for each script for this project, I've got
index.php
PHP Code:
<?php
require_once("../conf/config.inc.php");
require_once("../class/request.class.php");
require_once("../class/mysql.class.php");
$request = &new Request($_GET, $_POST);
if (!empty($request->get("loginkey"))) {
$user = &new User($request);
}
require_once("../templates/login.tpl.php");
?>
jobs.php
PHP Code:
<?php
require_once("../conf/config.inc.php");
require_once("../class/request.class.php");
require_once("../class/mysql.class.php");
$request = &new Request($_GET, $_POST);
$job = &new Job($request);
switch ($request->get("display")) {
case "joblist":
$job->setListHTML();
$jobTable = $job->getListHTML();
break;
case "job":
$job->setJobHTML();
$jobTable = $job->getJobHTML();
break;
default:
header("location:".SITE_URL."jobs.php?display=joblist");
break;
}
// jobs.tpl.php echos the $jobTable variable.
require_once("../templates/jobs.tpl.php");
?>
Down the track I'll be experimenting with using a controller class that intrinsicly makes the decision on what to display.
It's all just a matter of finding the time and inclination to do it I suppose.
I've also been trying to get my head around Test Driven Development. Where do I start? It's a concept I am finding hard to get a grasp of.
At which stage of the app design/development process do I decide to write tests?
But then again, I'll be looking into it later, when I've got a complete grasp of how OOP works.
Here's a few immediate questions however:
- Is there a better way to do this?
- Am I heading in the right direction?
- Should I have structured my classes differently?
- Have I made any fundamental app design errors?
- Does my snobbing off templating systems work for or against development?
Thanks in advance,
'cholic
Bookmarks