Java Design Patterns (2nd Edition) cover

Java Design Patterns (2nd Edition)

Rating 4.3
Word count
549 words
Chapters
39
ISBN
9787121178269

Tags

Summary

This book (original English edition: Design Patterns in Java, 2nd Edition) is a hands-on companion to the classic GoF work Design Patterns. Rather than merely restating the intent and structure of the 23 patterns one by one, the author uses Java as the vehicle and, through a sample project with a complete business context—Oozinoz, a simulated factory system that manufactures fireworks and firecrackers—demonstrates each pattern in realistic modeling, coding, and refactoring situations. Readers can clearly see a design evolve from something that merely "runs" into something that can be changed and extended. The book regroups the 23 patterns into five categories: interface, responsibility, construction, operation, and extension. Each category is preceded by an introductory chapter that first clarifies the problems shared by patterns of that type: how to choose between interfaces and abstract classes, how to assign responsibilities and control visibility, construction techniques beyond constructors, making operations and algorithms polymorphic, and eliminating code "bad smells" guided by the Open-Closed Principle, the Liskov Substitution Principle, and the Law of Demeter. This classification differs from GoF's three-way division into creational, structural, and behavioral patterns, and is closer to the practical thought process of asking which group of patterns to look for when a particular problem arises. Each pattern chapter includes a UML class diagram and runnable Java code, along with several exercises that guide readers to experience the applicable boundaries and costs of the patterns through hands-on rewriting. Four appendices at the end provide an exercise guide, answers to all exercises, a description of the Oozinoz source code, and a UML quick reference, allowing readers to verify their work on their own. This edition is the 2nd edition of the simplified Chinese version of the book, translated by Zhang Yi and Shi Lei.

Editor's review

市面上的设计模式书大致分两类:一类讲“模式是什么”,一类讲“模式怎么用”。这本书属于后者,而且属于很少见的那种——它不把 23 个模式当成 23 个知识点罗列,而是当成 23 把手术刀,让你在具体的代码病灶上反复练手。 最值得称道的是它的分类方式。作者打散 GoF 的创建型/结构型/行为型三分法,改按接口、职责、构造、操作、扩展五类重组,每一类前面先有一章导引,把这一类模式共同面对的困境讲透。这个顺序其实更接近工程师的真实处境:你很少会先想到“我要用一个结构型模式”,更多是“这个接口被我改得越来越乱”或者“这个类的构造参数已经十几个了”。 Oozinoz 这个贯穿全书的虚构工厂项目也选得聪明。它足够真实——有订单、有机器、有可视化界面、有数据库驱动、有解释器要解析的表达式语法,却不至于复杂到淹没模式本身。UML 图配 Java 代码,再配练习题和完整答案,是一本可以真正“做”完的书。 需要提醒的是,代码停留在 Java 5 前后的语境,注解、函数式接口、Stream 这些后来的东西不在此书讨论范围内。但对于想真正把模式内化成直觉的人,这反而是优点:它逼你回到对象、接口、多态这些本质问题上去思考,而不是用一行 lambda 遮住设计问题。

Who it's for

A good fit for

  • 已经能写 Java 代码、但设计上常常“写完就改不动”的中级开发者
  • 读过 GoF《设计模式》却不知道如何在项目中落地的读者
  • 准备重构遗留代码、需要一套判断标准的工程师
  • 讲授面向对象分析与设计、软件体系结构课程的教师与高年级学生

Not a good fit for

  • 完全没有 Java 与面向对象基础的初学者,本书不讲解语法与基本概念
  • 只想查阅模式定义速查表的读者,本书以练习驱动的讲解为主
  • 主要使用函数式风格或非面向对象语言的开发者,收获会相对有限

Reading tips

  1. 强烈建议先动手做每章练习再看附录 B 的答案,只读不做会损失本书大半价值。
  2. 配合原书 Oozinoz 源码边读边改,把示例代码跑起来再尝试重构。
  3. 按五个部分的顺序读,每部分导引章不要跳过,它决定了你理解模式的框架。
  4. 读完一种模式后,回到自己的项目寻找一处可以应用或反证它的代码。

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Chapter 1 Introduction
  2. Part 1 Interface Patterns
  3. Chapter 2 Introduction to Interface Patterns
  4. Chapter 3 Adapter Pattern
  5. Chapter 4 Facade Pattern
  6. Chapter 5 Composite Pattern
  7. Chapter 6 Bridge Pattern
  8. Part 2 Responsibility Patterns
  9. Chapter 7 Introduction to Responsibility Patterns
  10. Chapter 8 Singleton Pattern
  11. Chapter 9 Observer Pattern
  12. Chapter 10 Mediator Pattern
  13. Chapter 11 Proxy Pattern
  14. Chapter 12 Chain of Responsibility Pattern
  15. Chapter 13 Flyweight Pattern
  16. Part 3 Construction Patterns
  17. Chapter 14 Introduction to Construction Patterns
  18. Chapter 15 Builder Pattern
  19. Chapter 16 Factory Method Pattern
  20. Chapter 17 Abstract Factory Pattern
  21. Chapter 18 Prototype Pattern
  22. Chapter 19 Memento Pattern
  23. Part 4 Operation Patterns
  24. Chapter 20 Introduction to Operation Patterns
  25. Chapter 21 Template Method Pattern
  26. Chapter 22 State Pattern
  27. Chapter 23 Strategy Pattern
  28. Chapter 24 Command Pattern
  29. Chapter 25 Interpreter Pattern
  30. Part 5 Extension Patterns
  31. Chapter 26 Introduction to Extension Patterns
  32. Chapter 27 Decorator Pattern
  33. Chapter 28 Iterator Pattern
  34. Chapter 29 Visitor Pattern
  35. Appendix A Guide
  36. Appendix B Answers
  37. Appendix C Oozinoz Source Code
  38. Appendix D UML Overview
  39. References

FAQ

这本书和 GoF 的《设计模式》是什么关系?
它不是 GoF 原书的替代品,而是配套的实践手册。GoF 讲清 23 种模式的意图、结构与协作关系;本书则用 Java 项目把这些模式放进真实的设计与重构情境中演练,适合在读过或正在读 GoF 时同步使用。
书中的代码是什么 Java 版本?现在读会过时吗?
示例基于 Java 5 前后的语言特性,未涉及注解、lambda、Stream 等后起内容。模式的原理与结构不会过时,但具体写法需要读者自行迁移到现代 Java,这也正好是一个练习机会。
这本书的分类为什么和常见的三种类型不一样?
作者把 23 种模式重新划分为接口型、职责型、构造型、操作型、扩展型五类,目的是让每一类都对应一类实际设计困境,便于读者在遇到问题时快速定位该考虑哪组模式,而非按模式的静态结构归类。
Oozinoz 是什么?需要自己下载源码吗?
Oozinoz 是全书贯穿的虚构工厂项目,用于承载各个模式的示例场景。附录 C 说明了其源代码的组织方式,读者通常可以从配套渠道获取源码,边读边改比仅看纸质代码收获更大。
练习有答案吗?自学能看懂吗?
有。附录 A 是练习指南,附录 B 给出全部练习的参考答案,附录 D 是 UML 速览。自学时建议先独立完成再对照答案,附录 B 的存在使这本书可以脱离课堂独立使用。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category