Multiple Factories

Multiple Factories

Adding another factory interface into the mix is certainly within the spirit of this particular design pattern. For instance, many databases support the concept of transactions, which allow blocks of related queries to be treated (and, therefore, executed) as one for the purposes of ensuring the integrity of the underlying database. Interbase happens to be just such a database.

Figure 9-3 shows how transactions can be supported, and makes use of the factory interface to create them.

Figure 9-3

The InterbaseTransaction appears to work in a very similar fashion to the InterbaseQuery in that InterbaseConnection instantiates both of them. The lifecycle is somewhat different, however, since transactions typically outlive queries, as shown in the following sample code:

   $con = new InterbaseConnection();    $trans = $con->CreateTransaction();    $query = $con->query("delete from employee");    if ($query->error()) {       $trans->rollback();    } else {      $trans->commit();    } 

Professional PHP5 (Programmer to Programmer Series)
Professional PHP5 (Programmer to Programmer Series)
Year: 2003
Pages: 182
BUY ON AMAZON © 2008-2017.
If you may any questions please contact us: