Leveraging Existing Classes

Inheriting from the InterbaseConnection class is not only legal but also useful, as shown in Figure 9-4.


Figure 9-4

Notice the differences between InterbaseConnection and PersistentInterbaseConnection. First, note the use of ibase_connect vs ibase_pconnect to actually make the connection to the database server. Second, you'll note that PersistentInterbaseConnection has no need to close the physical connection in its destructor, because pconnect has assigned the class its database_handle from a pool of connections. In practice, this means that pconnect doe not require a corresponding ibase_close() function call to be made.

But because PersistentInterbaseConnection is being forced to make use of a regular InterbaseQuery in providing its exposed query method rather than, say, a fictitious InterbasePersistableQuery, it is totally reliant upon the generic InterbaseConnection factory interface for instantiation of the InterbaseQuery.

As a result, PersistentInterbaseConnection internally overrides InterbaseConnection's constructor and destructor, replacing the Interbase connections with Interbase persistent connections. This is a great example of adding functionally by extending an existing class structure, which is in turn the classic example of a factory method design pattern.



Professional PHP5 (Programmer to Programmer Series)
Professional PHP5 (Programmer to Programmer Series)
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 182
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net