Personal understanding: The adapter mainly acts as a mediator between the original function and the new function, which means that the new function must call some of the original functions. This improves code reusability. (If you understand it wrong, please give me some advice, thank you)
" Public function getError() __error; or}} Class Logtoconsole { Private $ __ errorObject;
Public Function __Construct ($ EERROROBject) ect = $ ERROROBJECT;
}
public function writing () {
- fwrite ("" errorlog.txt",$this->__errorObject->getError());
- } }
- }
- class logToCVS
- {
- const LOG_LOCATION='log.csv';
- errorObject )
- t;getErrorNumber();
- $line.=',';
- }
- }
- class logToCSVAdapter extends errorObject{ // Adapter
- use using using use using through out using off‐‐off off ‐ ‐ ‐‐ ‐ :",$this->getError ( )); {
- return $this->_errorNumber ;
- } b Public Function Geterrotext () {
- Return $ This-& GT; _ErrorText;
- }} // Write the error message to txt
- $ ERROR = New ErrorObject ("404: NOT Fun d ") ;
- $log=new logToConsole($error);
- $log->write();
- //Write error information to csv
- $error=new logToCSVAdapter("404:not fuond");
- $log =new logToCVS($error);
- $log->write();
- Copy code
|