[Typo3-dev] Alternative to hooks - fake "$this"

Frank Benkart frank.benkart at web.de
Thu Oct 28 20:58:08 CEST 2004


Hi Dan,
there is no parent class elsewhere. And there you are.... i don't want to
copy the code to a new class. Why should i doublicate it? It's been already
here.

And that is my thinking to make typo3 in the first way not normalised, the
first should be a refactoring of the core engine. Using real oop. If done
this, the second way is the normalisation.

I think the core engine should make the output, and the class do the
functions. Mean  generate public classes for getXXXX and setXXXX, all other
things are private.

Doing things like MFC (model view controller) or other patterns.

What do you think about that?

-------------------------------------
live strong - live typo3

"dan frost" <dan at danfrost.co.uk> schrieb im Newsbeitrag
news:mailman.1.1098967390.31376.typo3-dev at lists.netfielders.de...
> Two ways:
> - is there a parent class somewhere? or a similar class without the
> output generated at the bottom?
>
> - make a new, identical class in another file without the output
>
> I nearly did this myself with the db_list
>
> dan
>
> Frank Benkart [DIACC] wrote:
> > Hi Dan,
> > nice idea! I would like to test it.
> >
> > But how can I use the class typo3/move_el.php in my own extension?
> > When including this file, automatically an output is generated, because
the
> > file includes a class and the intantiating of this class. That's not e
rally
> > nice architecture....
> >
> > What do you think about this?
> >
> > ---------------------------------------------
> > live strong - live typo3
> >
> >
> > "dan frost" <dan at danfrost.co.uk> schrieb im Newsbeitrag
> > news:mailman.1.1098957618.12231.typo3-dev at lists.netfielders.de...
> >
> >>Dear all,
> >>
> >>Here's a trick i've used recently to fake the idea of hooks:
> >>
> >>First, we have a class which makes a query at some point:
> >>
> >>class first_class {
> >>   function main() {
> >>     //...do stuff
> >>
> >>     $query = '..something in here..';
> >>
> >>     //..do more stuff
> >>   }
> >>}
> >>
> >>To use this we would just do:
> >>
> >>$object = new first_class();
> >>$object->main();
> >>
> >>BUT! We need ot change the query. We shouldn't hack the code everytime
> >>the query changes because it's not nice. So, instead of making a hook we
> >>do three things:
> >>1. Move the query to a function
> >>2. create a reference variable in the class and point it to $this
> >>3. ask the reference variable for the query.
> >>
> >>That is:
> >>class first_class {
> >>   var $_this = null;
> >>
> >>   function first_class() {
> >>      $this->_this = &$this;
> >>   }
> >>
> >>   function main() {
> >>     //...do stuff
> >>
> >>     $query = $this->_this->query();
> >>
> >>     //..do more stuff
> >>   }
> >>
> >>   function query() {
> >>     return '..some query goes here...';
> >>   }
> >>}
> >>
> >>Which is used just the same way:
> >>$object = new first_class();
> >>$object->main();
> >>
> >>NOW... we want to change the query. This is done in two steps:
> >>1. create a second class with the function "query" in it
> >>2. reference $object->_this to our new class's object
> >>
> >>function second_class {
> >>   function query() {
> >>     return '...a different query...';
> >>   }
> >>}
> >>
> >>This is used by doing:
> >>
> >>$object = new first_class();
> >>$queryObject = new second_class();
> >>$object->_this = &$queryObject;
> >>$object->main();
> >>
> >>This query used will be the one in second_class.
> >>
> >>For most situations, this is idential to hook. But, it's a whole load
> >>nicer in many  situations. For example, where a class does a lot of
> >>things (e.g. split something, move something, sum something, delete
> >>something, then edit something, compare something and then archive it)
> >>having to go "if(is_array(...some var))... then call the object..." is
> >>boring.
> >>
> >>This method puts the responsibility for implementing the hook outside
> >>the class which does the work. Much nicer!
> >>
> >>dan
> >
> >
> >






More information about the TYPO3-dev mailing list