Ensures the automatic connection establishment, when a request is made.
class Connection { public: void request( const string & req ); // ... };
class Connector { public: Connection * connect(); // ... };
The Double-Try pattern is then,
TheConnector * connector; Connection * connection; { if ( connection ) { try { connection->request( ... ); } catch ( ConnectionException & e ) { delete connection; } } if ( ! connection ) { try { connection = connector->connect(); connection->request( ... ); } catch ( ConnectionException & e ) { if ( connection ) delete connection; // safe backup for request failure } } }
Marco Corvi - Page hosted by geocities.com.