On 13 April 2010 17:25, Ryan Sun <ryansu...@gmail.com> wrote:
> this is a class for corntab job, and the validation is very simple,
> just check if the status of user is active when cron job runs, if not,
> throws an exception, other developers won't want to overwrite this
> validation.
> which method of user class will be called is configurable via website
> backed page(we write the name of methods directly in to  schedule
> table).
> Using private methods will solve the problem but since we write public
> methods for all the other cron classes, I just want to keep the style
> to make less confusion.
> On Tue, Apr 13, 2010 at 12:11 PM, Nathan Rixham <nrix...@gmail.com> wrote:
>> Ryan Sun wrote:
>>> I'm writing an abstract parent class which only contain a validate
>>> method, other developers will extend this class and add many new
>>> public methods, every new methods will need to perform a validate
>>> first.  Won't it be good if validate get called automatically before
>>> every method call so that they don't have to write more code and they
>>> won't miss this validate?
>> This may call for a back to roots approach, what exactly are you trying
>> to accomplish, as in: what is the validation doing?
>> perhaps if we see the full picture, we can recommend another perhaps
>> more suited approach to the full thing, feel free to post the full code
>> if you want / can, the more info the better!
>> Regards,
>> Nathan
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Would this be better ...

abstract class baseValidate() {
 final public function __construct($params) {
  // Determine if user is active.
 // If OK, then call abstract function postConstruct($params)

 abstract function postConstruct($params);

You can't override the constructor, so the validation will always be
called. The developer's can implement their own postConstruct as if
they where extending __construct.

Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to