IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

设计模式(六):适配器模式

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

68_1.png

优点:

  ① 通过引入一个适配器Adapter来重用现有的不兼容的旧类Adeptee,而无需修改旧类原有结构。

  ② 增加了旧类的复用性;适配器的灵活性和扩展性都非常好

缺点:

  ① 一次最多只能适配一个旧类,不能同时适配多个旧类。

适用范围:需要有旧类,而旧类的接口不符合新系统的需要,甚至旧类都没有源代码

  

客户端:  

  Player b = new ForWards(“巴蒂尔”);
  b.attack(); // 进攻命令(英文)

  //作废
  // Player y = new Center(“姚明”);
  // y.attack();

  Player ym = new Translator(“姚明”); //适配器,此处相当于翻译
  ym.attack(); // 进攻命令(已适配为中文)

一句话概括:如同一个电源适配器,不论什么电压,只要经过适配器,都能变成适合的220V

    /**
     * Player                     (进攻、防守抽象方法)
     * ForWords  Center  Guards   (实例化Player接口)  -- 本国队员
     * 
     * ForeignCenter (旧类,没有实现Player接口,但包含有类似的进攻、防守的方法)  --  外国队员
     * 
     * Translator (适配器,同样实例化Player接口,然后将旧类属性及方法放入此适配器,用来代替旧类)  --  本国队员(已转化)
     */

文章永久链接:https://tech.souyunku.com/?p=20307


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(85) 打赏



未经允许不得转载:搜云库技术团队 » 设计模式(六):适配器模式

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367