《大话设计模式【Java溢彩加强版】》延续了前作轻松调侃的风格,采用了师生对话的方式展开讨论,其中穿插了大量“接地气”的类比案例,帮助大家迅速“开窍”,作者精心将本书图表制作成彩色三维形式,阅读起来你会发现,不仅仅是养眼,对一些流程、概念的解说,用彩色三维图表更为精准,学习体验有了质变。
在上一版出版至今的长达15年里,本书一直是国内原创计算机类图书畅销榜霸榜产品。不过本书前作确实存在一些不足和缺憾,有很大提升空间。
此次升级对书中的大量细节做了更新,增补或者替换了更加便于理解的解读和案例。
对原书中工厂方法模式的内容进行了彻底重写。
对部分章节,如装饰模式、观察者模式、抽象工厂模式、单例模式等内容做了较大改动。
对很多模式的讲解内容和代码样例做了完善,比如同一个商场收银程序的不断迭代升级在策略模式、装饰模式、工厂方法模式、抽象工厂模式章节中都有体现。
增加了超过100页的全效PPT学习课件。
全书的所有图表用颜色和立体效果进行了重新定义。
......(更多)
程杰,一个被读者誉为很适合写IT技术书的家伙。
著有 《大话数据结构》(霸榜12年,知乎推荐、B站解书常客。开创了一种适合中国人阅读的趣味讲解IT知识的风格与模式)。
作者参与过政府机构、证券、游戏、交通等多种行业的软件开发及项目管理工作,也曾做过软件培训的教师,目前从事教育类APP/微信小程序的开发与运营。因为有过两年半高中数学教学的独特经历,使得其书作当中处处以初学者视角考虑和分析问题,成为了当前很受欢迎的IT技术图书作者之一。
......(更多)
目 录
第0章 楔子 培训实习生—面向对象基础 ························1
0.1 培训实习生 ·······························1
0.2 类与实例 ··································2
0.3 构造方法 ··································4
0.4 方法重载 ··································6
0.5 属性与修饰符 ····························7
0.6 封装 ········································9
0.7 继承 ······································10
0.8 多态 ······································14
0.9 重构 ······································18
0.10 抽象类 ··································20
0.11 接口 ·····································22
0.12 集合 ·····································27
0.13 泛型 ·····································29
0.14 客套 ·····································31
第1章 代码无错就是优?—简单工厂模式 ······················32
1.1 面试受挫 ································32
1.2 初学者代码毛病 ·······················33
1.3 代码规范 ································34
1.4 面向对象编程 ··························34
1.5 活字印刷,面向对象 ·················35
1.6 面向对象的好处 ·······················37
1.7 复制 vs. 复用····························37
1.8 业务的封装 ·····························38
1.9 紧耦合 vs. 松耦合······················40
1.10 简单工厂模式 ·························42
1.11 UML类图 ······························43
第2章 商场促销—策略模式 ········································48
2.1 商场收银软件 ··························48
2.2 增加打折 ································49
2.3 简单工厂实现 ··························50
2.4 策略模式 ································53
2.5 策略模式实现 ··························55
2.6 策略与简单工厂结合 ·················57
2.7 策略模式解析 ··························58
第3章 电子阅读器 vs. 手机—单一职责原则 ···················60
3.1 阅读干吗不直接用手机? ···········60
3.2 手机不纯粹 ·····························60
XV
目 录
3.3 电子阅读器 vs. 手机···················61
3.4 单一职责原则 ··························62
3.5 方块游戏的设计 ·······················62
3.6 电子阅读器与手机的利弊 ···········65
第4章 考研求职两不误—开放-封闭原则 ························66
4.1 考研失败 ································66
4.2 开放-封闭原则 ·························67
4.3 何时应对变化 ··························69
4.4 两手准备,并全力以赴 ··············70
第5章 会修电脑不会修收音机?—依赖倒转原则 ·············72
5.1 MM请求修电脑 ························72
5.2 电话遥控修电脑 ·······················73
5.3 依赖倒转原则 ··························74
5.4 里氏代换原则 ··························77
5.5 修收音机 ································78
第6章 穿什么有这么重要?—装饰模式 ·························80
6.1 穿什么有这么重要? ·················80
6.2 小菜扮靓第一版 ·······················81
6.3 小菜扮靓第二版 ·······················83
6.4 装饰模式 ································85
6.5 小菜扮靓第三版 ·······················88
6.6 商场收银程序再升级 ·················91
6.7 简单工厂+策略+装饰模式实现 ·····92
6.8 装饰模式总结 ··························96
第7章 为别人做嫁衣—代理模式 ··································98
7.1 为别人做嫁衣! ·······················98
7.2 没有代理的代码 ······················100
7.3 只有代理的代码 ······················101
7.4 符合实际的代码 ······················102
7.5 代理模式 ·······························104
7.6 代理模式应用 ·························105
7.7 秀才让小六代其求婚 ················106
第8章 工厂制造细节无须知—工厂方法模式 ·················107
8.1 需要了解工厂制造细节吗? ·······107
8.2 简单工厂模式实现 ···················108
8.3 工厂方法模式实现 ···················109
8.4 简单工厂 vs. 工厂方法 ··············110
8.5 商场收银程序再再升级 ·············115
8.6 简单工厂+策略+装饰+工厂方法 ··116
XVI
大话设计模式 | 【Java溢彩加强版】
第9章 简历复印—原型模式 ······································120
9.1 夸张的简历 ····························120
9.2 简历代码初步实现 ···················121
9.3 原型模式 ·······························123
9.4 简历的原型实现 ······················125
9.5 浅复制与深复制 ······················126
9.6 简历的深复制实现 ···················129
9.7 复制简历 vs. 手写求职信 ···········130
第10章 考题抄错会做也白搭—模板方法模式 ···············132
10.1 选择题不会做,蒙呗! ············132
10.2 重复=易错+难改 ·····················133
10.3 提炼代码 ······························135
10.4 模板方法模式 ························138
10.5 模板方法模式的特点 ···············140
10.6 主观题,看你怎么蒙 ···············140
第11章 无熟人难办事?—迪米特法则 ························141
11.1 第一天上班 ···························141
11.2 无熟人难办事 ························142
11.3 迪米特法则 ···························144
第12章 牛市股票还会亏钱?—外观模式 ·····················145
12.1 牛市股票还会亏钱? ···············145
12.2 股民炒股代码 ························146
12.3 投资基金代码 ························147
12.4 外观模式 ······························149
12.5 何时使用外观模式 ··················150
第13章 好菜每回味不同—建造者模式 ························152
13.1 炒面没放盐 ···························152
13.2 建造小人一 ···························154
13.3 建造小人二 ···························155
13.4 建造者模式 ···························156
13.5 建造者模式解析 ·····················159
13.6 建造者模式基本代码 ···············160
第14章 老板回来,我不知道—观察者模式 ··················162
14.1 老板回来?我不知道! ············162
14.2 双向耦合的代码 ·····················163
14.3 解耦实践一 ···························165
14.4 解耦实践二 ···························167
14.5 观察者模式 ···························170
14.6 观察者模式的特点 ··················172
14.7 Java内置接口实现 ···················173
14.8 观察者模式的应用 ··················177
14.9 石守吉失手机后 ·····················178
第15章 就不能不换DB吗?—抽象工厂模式 ·················179
15.1 就不能不换DB吗? ·················179
15.2 最基本的数据访问程序 ············181
15.3 用了工厂方法模式的数据访问
程序 ····································182
15.4 用了抽象工厂模式的数据访问
程序 ····································185
15.5 抽象工厂模式 ························188
15.6 抽象工厂模式的优点与缺点 ······189
15.7 用简单工厂来改进抽象工厂 ······190
15.8 用反射+抽象工厂的数据访问
程序 ····································192
15.9 用反射+配置文件实现数据访问
程序 ····································194
15.10 商场收银程序再再再升级 ·······195
15.11 无痴迷,不成功····················198
第16章 无尽加班何时休—状态模式 ···························199
16.1 加班,又是加班! ··················199
16.2 工作状态 — 函数版 ·············200
16.3 工作状态 — 分类版 ·············201
16.4 方法过长是坏味道 ··················203
16.5 状态模式 ······························203
16.6 状态模式的好处与用处 ············205
16.7 工作状态 — 状态模式版 ·······206
第17章 在NBA我需要翻译—适配器模式 ·····················209
17.1 在NBA我需要翻译! ···············209
17.2 适配器模式 ···························210
17.3 何时使用适配器模式 ···············212
17.4 篮球翻译适配器 ·····················213
17.5 适配器模式的.NET应用 ···········216
17.6 扁鹊的医术 ···························217
第18章 如果再回到从前—备忘录模式 ························218
18.1 如果再给我一次机会…… ·········218
18.2 游戏存进度 ···························219
18.3 备忘录模式 ···························221
18.4 备忘录模式基本代码 ···············222
18.5 游戏进度备忘 ························224
大话设计模式 | 【Java溢彩加强版】
第19章 分公司=一部门—组合模式 ····························227
19.1 分公司不就是一部门吗? ·········227
19.2 组合模式 ······························229
19.3 透明方式与安全方式 ···············231
19.4 何时使用组合模式 ··················232
19.5 公司管理系统 ························233
19.6 组合模式好处 ························235
第20章 想走?可以!先买票—迭代器模式 ··················237
20.1 乘车买票,不管你是谁! ·········237
20.2 迭代器模式 ···························239
20.3 迭代器实现 ···························240
20.4 Java的迭代器实现 ···················243
20.5 迭代高手 ······························244
第21章 有些类也需计划生育—单例模式 ·····················245
21.1 类也需要计划生育 ··················245
21.2 判断对象是否是null ················246
21.3 生还是不生是自己的责任 ·········249
21.4 单例模式 ······························251
21.5 多线程时的单例 ·····················253
21.6 双重锁定 ······························254
21.7 静态初始化 ···························255
第22章 手机软件何时统一—桥接模式 ························257
22.1 凭什么你的游戏我不能玩 ·········257
22.2 紧耦合的程序演化 ··················258
22.3 合成/聚合复用原则 ·················262
22.4 松耦合的程序 ························263
22.5 桥接模式 ······························265
22.6 桥接模式基本代码 ··················267
22.7 我要开发“好”游戏 ···············268
第23章 烤羊肉串引来的思考—命令模式 ·····················269
23.1 吃烤羊肉串! ························269
23.2 烧烤摊 vs. 烧烤店 ···················270
23.3 紧耦合设计 ···························271
23.4 命令模式 ······························272
23.5 松耦合设计 ···························274
23.6 进一步改进命令模式 ···············276
23.7 命令模式的作用 ·····················278
第24章 加薪非要老总批?—职责链模式 ·····················279
24.1 老板,我要加薪! ··················279
24.2 加薪代码初步 ························280
24.3 职责链模式 ···························282
24.4 职责链的好处 ························284
24.5 加薪代码重构 ························284
24.6 加薪成功 ······························287
第25章 世界需要和平—中介者模式 ···························289
25.1 世界需要和平! ·····················289
25.2 中介者模式 ···························291
25.3 安理会作中介 ························293
25.4 中介者模式的优缺点 ···············295
第26章 项目多也别傻做—享元模式 ···························298
26.1 项目多也别傻做! ··················298
26.2 享元模式 ······························300
26.3 网站共享代码 ························302
26.4 内部状态与外部状态 ···············304
26.5 享元模式应用 ························306
第27章 其实你不懂老板的心—解释器模式 ··················309
27.1 其实你不懂老板的心 ···············309
27.2 解释器模式 ···························310
27.3 解释器模式的好处 ··················313
27.4 音乐解释器 ···························313
27.5 音乐解释器实现 ·····················315
27.6 料事如神 ······························319
第28章 男人和女人—访问者模式 ······························320
28.1 男人和女人! ························320
28.2 最简单的编程实现 ··················321
28.3 简单的面向对象实现 ···············322
28.4 用了模式的实现 ·····················324
28.5 访问者模式 ···························327
28.6 访问者模式基本代码 ···············328
28.7 比上不足,比下有余 ···············330
第29章 OOTV杯超级模式大赛—模式总结 ···················331
29.1 演讲任务 ······························331
29.2 报名参赛 ······························332
29.3 超模大赛开幕式 ·····················333
29.4 创建型模式比赛 ·····················337
29.5 结构型模式比赛 ·····················342
29.6 行为型模式一组比赛 ···············350
29.7 行为型模式二组比赛 ···············356
29.8 决赛 ····································361
29.9 梦醒时分 ······························365
29.10 没有结束的结尾 ···················366
参考文献···································································367
......(更多)
策略模式(Strategy):它定义了算法的家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。 -Disign Pattern
单例模式(singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点。
......(更多)