获取天气-步骤9-解耦

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取天气-步骤9-解耦相关的知识,希望对你有一定的参考价值。

  1. //decoupling:
  2. //changing the inner impl of MemCache without affecting the
  3. //consumers...they get what they need without KNOWING or CARING about
  4. //the inner implementation of MemCache...
  5.  
  6. class MemCache extends BaseCache{
  7.  
  8. //define("MEM_CACHE_SESSION_KEY", "__memcachesessionkey");
  9.  
  10. public function MemCache(){
  11. //some intitialization here...
  12. }
  13.  
  14. public function get($key){
  15. if (!array_key_exists($key, $_SESSION[MEM_CACHE_SESSION_KEY]))
  16. return $_SESSION[MEM_CACHE_SESSION_KEY];
  17.  
  18. //else
  19. echo "Huston we have a problem!";
  20. }
  21.  
  22. public function set($key, $val){
  23. if (array_key_exists($key, $_SESSION[MEM_CACHE_SESSION_KEY]))
  24. echo "Huston...just to let you know that an override occurs here to $key with val: $val";
  25.  
  26. $_SESSION[MEM_CACHE_SESSION_KEY][$key] = $val;
  27. }
  28. }

以上是关于获取天气-步骤9-解耦的主要内容,如果未能解决你的问题,请参考以下文章

Java 9 模块解耦的设计策略

不要把分层当做解耦!

httpclient获取响应实体和信息的封装方法(解耦更新)

程序的耦合和解耦

Django - 无法从“解耦”导入名称“配置”

Struts2中的Action类(解耦方式,耦合方式)