Hi, thanks for your suggestion!
Thomas Koch wrote:
> I consider it to be very important for clean code to separate the input
> validation from any action or logic. This can be best reached by having
> different methods for this two tasks.
I agree with that (although it is not the most important, i'll come back to that
later).
> The actual controller action method should be invoked only with verified
> data and should not have to care whether the data is clean. This could
> be reached by putting the input data in individual request objects which
> are guarentied to contain only verified data:
> 
> class myBookingDataConfirmationController
> {
>     public function run( myBookingDataStruct $data )
> }
You might be interrested in the new design (which is not implemented in this
controller).
> A separate method class is responsible to validate the request data
> and to build a myBookingDataStruct from the request. Think of an
> ezcInputForm class as an example for such a validator.
> 
> Because the validation could fail, we need another method in the
> controller:
> 
> public function onValidationFailed( myValidator $failedValidator, 
> ezcMvcRequest $request )
> 
> This method is then responsible for showing the error message.
> 
> The magic validator should also be provided by the controller, like:
> 
> public function getValidator( $protocoll )
> 
> I think that it would also be handy for SOAP interfaces to exactly
> specify the kind of data that a controller expects. 
That is nice and you are free to implement it ;)

As a user of MvcTools since it's early versions, i have a quite good tip to
share: try not to tie in any component in your controllers.

Here a design patten demonstration, i don't know its name, please tell me if you
do.

http://svn.ez.no/svn/ezcomponents/experimental/MvcTools/design/model_controller_loose_coupling_example.svg

Of course, you can make your contoller to depend on
yourInputValidationServiceInterface, and couple UserInput with
yourInputValidationServiceImplementation.

In that case, your controller is loosly coupled with UserInput.

Regards, James.
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to