Design Patterns (Adapters)

WBOY
Release: 2016-07-25 08:47:37
Original
1069 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. class logToCSVAdapter extends errorObject{ // Adapter
  13. use using using use using through out using off‐‐off off ‐ ‐ ‐‐ ‐ :",$this->getError ( )); {
  14. return $this->_errorNumber ;
  15. } b Public Function Geterrotext () {
  16. Return $ This-& GT; _ErrorText;
  17. }} // Write the error message to txt
  18. $ ERROR = New ErrorObject ("404: NOT Fun d ") ;
  19. $log=new logToConsole($error);
  20. $log->write();
  21. //Write error information to csv
  22. $error=new logToCSVAdapter("404:not fuond");
  23. $log =new logToCVS($error);
  24. $log->write();
  25. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!