
Originally Posted by
Dr Livingston
There seams to be a lot of IF/ELSE conditions in the various class methods which I find is a bad choice. My thinking is that each condition in it's self, ie The logic would actually be it's own controller instead?
As stated earlier there is a cascade/hierarchy structure, so this is how I'd structure it, leaveing the selection process down to a CoR.
Yes, CoR also came to my mind after reading arborints post. I would say that the latest post by me implements exactly what you described above.
The MyForm is an ApplicationController. When executed it will dispatch to a new controller - either a ServerPage (forminit.php) or to another ApplicationController (submithandler). The second ApplicationController (submithandler) will then in turn dispatch to one of two serverpages (formdone.php) or (forminvalid.php). The hierarchy could be made a lot more complex if needed, by simply adding new ApplicationControllers in lieu of a ServerPage.
The only real limitation of this design is that each ApplicationController could only make a boolean decision (true | false), but as far as I know formal logic any decision could be reduced to a tree of boolean assertions.
My example probably is a bit messy, since one ApplicationController (MyForm) is created through inheritance, while the other (submithandler) is created through composition. The diagram below should illustrate what is going on.
Edit:
Here's the same example, but using composition for creating both ApplicationControllers
PHP Code:
class FormController
{
var $_submitController;
var $_formController;
function FormController(&$initHandler, &$failHandler, &$okHandler) {
$this->_submitController =& new ApplicationController($okHandler, $failHandler, REQUEST_METHOD_POST);
$this->_formController =& new ApplicationController($this->_submitController, $initHandler, REQUEST_METHOD_POST);
}
function addFilter(&$filter) {
$this->_formController->addFilter($filter);
}
function addRule(&$rule) {
$this->_submitController->addRule($rule);
}
function execute(&$request, &$response) {
$this->_formController->execute($request, $response);
}
} // end class FormController
PHP Code:
class MyForm extends FormController
{
function MyForm() {
parent::FormController(
new ServerPage("page/forminit.php"),
new ServerPage("page/forminvalid.php"),
new ServerPage("page/formdone.php")
);
$this->addRule(new Rule_Required("foo"));
$this->addRule(new Rule_Email("foo"));
}
} // end class MyForm
Edit:
Reuse ApplicationController from post #41.
Perhaps the class currently called ApplicationController should be renamed to something like FlowController ?
Bookmarks