Home > Backend Development > PHP Tutorial > Design Patterns (Adapters)

Design Patterns (Adapters)

WBOY
Release: 2016-07-25 08:47:37
Original
1157 people have browsed it
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 () {
  1. fwrite ("" errorlog.txt",$this->__errorObject->getError());
  2. } }
  3. }
  4. class logToCVS
  5. {
  6.       const LOG_LOCATION='log.csv';
  7.                                  errorObject )
  8.                                                                                                                                                                                                                                 t;getErrorNumber();
  9.                   $line.=',';
  10.                                                                                                                                                                                       }
  11.      
  12. }
  13. class logToCSVAdapter extends errorObject{ // Adapter
  14.                                                         use using       using           use using      through out using off‐‐off off ‐ ‐ ‐‐ ‐                                                  :",$this->getError ( )); {
  15.                   return $this->_errorNumber ;
  16. } b Public Function Geterrotext () {
  17. Return $ This-& GT; _ErrorText;
  18. }} // Write the error message to txt
  19. $ ERROR = New ErrorObject ("404: NOT Fun d ") ;
  20. $log=new logToConsole($error);
  21. $log->write();
  22. //Write error information to csv
  23. $error=new logToCSVAdapter("404:not fuond");
  24. $log =new logToCVS($error);
  25. $log->write();
  26. Copy code
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template