设计模式已经成为面向对象设计和编程的主要内容,它为解决人们经常遇到的编程问题提供了易于重用且可维护的高级方案。本书介绍了23种设计模式,对于每一种模式,都至少提供了一个完整的可视化Java程序,使Java程序员迅速上手。\r\n\r\n 本书通俗易懂,方便读者理解设计模式的本质和目的。本书适用于Java程序员和自学者。\r\n
\r\n
Preface \r\n\r\n Acknowledgments \r\n\r\n Section 1 What Are Design Patterns? \r\n\r\n Chapter 1 Introduction \r\n\r\n Defining Design Patterns \r\n\r\n The Learning Process \r\n\r\n Studying Design Patterns \r\n\r\n Notes on Object-Oriented Approaches \r\n\r\n The Java Foundation Classes \r\n\r\n Java Design Patterns \r\n\r\n Chapter 2 UML Diagrams \r\n\r\n Inheritance \r\n\r\n Interfaces \r\n\r\n Composition \r\n\r\n Annotation \r\n\r\n JVISION UML Diagrams \r\n\r\n Visual SlickEdit Project Files \r\n\r\n Section 2 Creational Patterns \r\n\r\n Chapter 3 The Factory Pattern \r\n\r\n How a Factory Works \r\n\r\n Sample Code \r\n\r\n The Two Subclasses \r\n\r\n Building the Simple Factory \r\n\r\n Factory Patterns in Math Computation \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 4 The Factory Method \r\n\r\n The Swimmer Class \r\n\r\n The Event Classes \r\n\r\n Straight Seeding \r\n\r\n Our Seeding Program \r\n\r\n Other Factories \r\n\r\n When to Use a Factory Method \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 5 The Abstract Factory Pattern \r\n\r\n A GardenMaker Factory \r\n\r\n How the User Interface Works \r\n\r\n Adding More Classes \r\n\r\n Consequences of the Abstract Factory Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 6 The Singleton Pattern \r\n\r\n Creating a Singleton Using a Static Method \r\n\r\n Exceptions and Instances \r\n\r\n Throwing an Exception \r\n\r\n Creating an Instance of the Class \r\n\r\n Providing a Global Point of Access to a Singleton Pattern \r\n\r\n The javax.comm Package as a Singleton \r\n\r\n Other Consequences of the Singleton Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 7 The Builder Pattern \r\n\r\n An Investment Tracker \r\n\r\n Calling the Builders \r\n\r\n The List Box Builder \r\n\r\n The Check Box Builder \r\n\r\n Consequences of the Builder Pattern \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 8 The Prototype Pattern \r\n\r\n Cloning in Java \r\n\r\n Using the Prototype \r\n\r\n Using the Prototype Pattern \r\n\r\n Prototype Managers \r\n\r\n Cloning Using Serialization \r\n\r\n Consequences of the Prototype Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Summary of Creational Patterns \r\n\r\n Section 3 Structural Patterns \r\n\r\n Chapter 9 The Adapter Pattern \r\n\r\n Moving Data between Lists \r\n\r\n Using the JFC JList Class \r\n\r\n Two-Way Adapters \r\n\r\n Pluggable Adapters \r\n\r\n Adapters in Java \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 10 The Bridge Pattern \r\n\r\n The Class Diagram \r\n\r\n Extending the Bridge \r\n\r\n Java Beans as Bridges \r\n\r\n Consequences of the Bridge Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 11 The Composite Pattern \r\n\r\n An Implementation of a Composite \r\n\r\n Computing Salaries \r\n\r\n The Employee Classes \r\n\r\n The Boss Class \r\n\r\n Building the Employee Tree \r\n\r\n Self-Promotion \r\n\r\n Doubly Linked List \r\n\r\n Consequences of the Composite Pattern \r\n\r\n A Simple Composite \r\n\r\n Composites in Java \r\n\r\n Other Implementation Issues \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 12 The Decorator Pattern \r\n\r\n Decorating a CoolButton \r\n\r\n Using a Decorator \r\n\r\n The Class Diagram \r\n\r\n Decorating Borders in Java \r\n\r\n Nonvisual Decorators \r\n\r\n Decorators, Adapters, and Composites \r\n\r\n Consequences of the Decorator Pattern \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 13 The Facade Pattern \r\n\r\n Building the Facade Classes \r\n\r\n Consequences of the Facade Pattern \r\n\r\n Notes on Installing and Running the dbFrame Program \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 14 The FI)weight Pattern \r\n\r\n Discussion \r\n\r\n Example Code \r\n\r\n Flyweight Uses in Java \r\n\r\n Sharable Objects \r\n\r\n Copy-on-Write Objects \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 15 The Proxy Pattern \r\n\r\n Sample Code \r\n\r\n Copy-on-Write \r\n\r\n Enterprise Java Beans \r\n\r\n Comparison with Related Patterns \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Summary of Structural Patterns \r\n\r\n Section 4 Behavioral Patterns \r\n\r\n Chapter 16 Chain of Responsibility Pattern \r\n\r\n Applicability \r\n\r\n Sample Code \r\n\r\n The List Boxes \r\n\r\n Programming a Help System \r\n\r\n A Chain or a Tree? \r\n\r\n Kinds of Requests \r\n\r\n Examples in Java \r\n\r\n Consequences of the Chain of Responsibility \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 17 The Command Pattern \r\n\r\n Motivation \r\n\r\n Command Objects \r\n\r\n Building Command Objects \r\n\r\n The Command Pattern \r\n\r\n The Command Pattern in the Java Language \r\n\r\n Consequences of the Command Pattern \r\n\r\n Providing Undo \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 18 The Interpreter Pattern \r\n\r\n Motivation \r\n\r\n Applicability \r\n\r\n Simple Report Example \r\n\r\n Interpreting the Language \r\n\r\n Objects Used in Parsing \r\n\r\n Reducing the Parsed Stack \r\n\r\n Implementing the Interpreter Pattern \r\n\r\n Consequences of the Interpreter Pattern \r\n\r\n Thought Question \r\n\r\n programs on the CD-ROM \r\n\r\n Chapter 19 The Iterator Pattern \r\n\r\n Motivation \r\n\r\n Enumerations in Java \r\n\r\n Sample Code \r\n\r\n Filtered Iterators \r\n\r\n Consequence of the Iterator Pattern \r\n\r\n Composites and Iterators \r\n\r\n Iterators in Java 1.2 \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 20 The Mediator Pattern \r\n\r\n An Example System \r\n\r\n Interactions between Controls \r\n\r\n Sample Code \r\n\r\n Mediators and Command Objects \r\n\r\n Consequences of the Mediator Pattern \r\n\r\n Single Interface Mediators \r\n\r\n Implementation Issues \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 21 The Memento Pattern \r\n\r\n Motivation \r\n\r\n Implementation \r\n\r\n Sample Code \r\n\r\n Consequences of the Memento Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 22 The Observer Pattern \r\n\r\n Watching Colors Change \r\n\r\n The Message to the Media \r\n\r\n The JList as an Observer \r\n\r\n The MVC Architecture as an Observer \r\n\r\n The Observer Interface and Observable Class \r\n\r\n Consequences of the Observer Pattern \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 23 The State Pattern \r\n\r\n Sample Code \r\n\r\n Switching between States \r\n\r\n How the Mediator Interacts with the StateManager \r\n\r\n State Transitions \r\n\r\n Mediators and the God Class \r\n\r\n Consequences of the State Pattern \r\n\r\n Thought Questions \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 24 The Strategy Pattern \r\n\r\n Motivation \r\n\r\n Sample Code \r\n\r\n The Context Class \r\n\r\n The Program Commands \r\n\r\n The Line and Bar Graph Strategies \r\n\r\n Drawing Plots in Java \r\n\r\n Consequences of the Strategy Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 25 The Template Pattern \r\n\r\n Motivation \r\n\r\n Kinds of Methods in a Template Class \r\n\r\n Template Method Patterns in Java \r\n\r\n Sample Code \r\n\r\n Templates and Callbacks \r\n\r\n Consequences of the Template Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 26 The Visitor Pattern \r\n\r\n Motivation \r\n\r\n When to Use the Visitor Pattern \r\n\r\n Sample Code \r\n\r\n Visiting the Classes \r\n\r\n Visiting Several Classes \r\n\r\n Bosses are Employees, Too \r\n\r\n Catch-All Operations Using Visitors \r\n\r\n Double Dispatching \r\n\r\n Traversing a Series of Classes \r\n\r\n Consequence of the Visitor Pattern \r\n\r\n Thought Question \r\n\r\n Programs on the CD-ROM \r\n\r\n Section 5 Design Patterns and the Java Foundation Classes \r\n\r\n Chapter 27 The JFC, or Swing \r\n\r\n Installing and Using Swing \r\n\r\n Ideas behind Swing \r\n\r\n The Swing Class Hierarchy \r\n\r\n Chapter 28 Writing a Simple JFC Program \r\n\r\n Setting the Look and Feel \r\n\r\n Setting the Window Close Box \r\n\r\n Making a JxFrame Class \r\n\r\n A Simple Two-Button Program \r\n\r\n More on JButton \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 29 Radio Buttons and Toolbars \r\n\r\n Radio Buttons \r\n\r\n The JToolBar \r\n\r\n JToggleButton \r\n\r\n A Sample Button Program \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 30 Menus andActions \r\n\r\n Action Objects \r\n\r\n Design Patterns in the Action Object \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 31 The JList Class \r\n\r\n List Selections and Events \r\n\r\n Changing a List Display Dynamically \r\n\r\n A Sorted JList with a ListModel \r\n\r\n Sorting More-Complicated Objects \r\n\r\n Getting Database Keys \r\n\r\n Adding Pictures in List Boxes \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 32 The JTable Class \r\n\r\n A Simple JTable Program \r\n\r\n Cell Renderers \r\n\r\n Rendering Other Kinds of Classes \r\n\r\n Selecting Cells in a Table \r\n\r\n Patterns Used in This Image Table \r\n\r\n Programs on the CD-ROM \r\n\r\n Chapter 33 The JTree Class \r\n\r\n The TreeModel Interface \r\n\r\n Programs on the CD-ROM \r\n\r\n Summary \r\n\r\n Section 6 Case Studies \r\n\r\n Chapter 34 Sandy and the Mediator \r\n\r\n Chapter 35 Herb's Text Processing Tangle \r\n\r\n Chapter 36 Mary's Dilemma \r\n\r\n Bibliography \r\n
\r\n
程序设计在于处理复杂性:问题的复杂性和所用的程序设计工具的复杂性. Java的魅力在于其本身的低复杂性, 同时又能很好地处理高度复杂的问题. Java程序的开发周期只有类似的C++程序的一半甚至更少, 而且Java可以方便地处理复杂软件问题:多线程. 分布式. 跨平台. 安全性等. Java从诞生到现在, 已经广泛应用于几乎所有类型软件系统的构建. 尤其在基于Web的系统开发中, Java技术具有独特的优势. 熟悉Java历史的人都知道, Java的前身——编程语言Oak就是致力于电子产品互连的语言, Internet的发展导致了Oak的重生和Java的广为流行. 现在, J2EE技术已经成为企业级Web应用系统的标准平台.
好的程序设计人员不仅仅要掌握优秀的编程工具, 更需要掌握优秀的编程思想. 随着面向对象编程技术数十年的发展, 人们开始提炼和总结面向对象编程中行之有效的. 具有一定普遍意义的方法, 即面向对象的设计模式. 以Gamma. Helm. Johnson和Vlissides合著的经典书籍《设计模式》为开端, 面向对象设计模式的研究和应用成为面向对象程序设计的重要内容. 所有结构良好的面向对象软件系统都包含了大量的设计模式, 能否熟练应用设计模式已经成为衡量程序员水平的至关重要的标准.
本丛书收录了与Java程序设计和Java设计模式相关的经典书籍, 反映了应用Java开发软件系统的最佳经验总结和最新动态.
《Java设计模式》采用方便而简洁的编写风格, 以可视化的Java程序为例, 详细介绍了Gamma. Helm. Johnson和Vlissides合著的经典书籍《设计模式》中列出的所有23种模式. 通过本书, Java程序员可以迅速了解和掌握设计模式的内容, 并在实践中应用设计模式来创建复杂而健壮的Java程序.
《Java模式应用》介绍了基于模式的开发技巧, 演示了使用Java开发各种商务系统中的模式应用. 书中首先概述设计模式, 然后就四种主要模式——创建模式. 行为模式. 结构模式和系统模式展开了详细的论述. 该书还针对系统构建过程中常用的J2EE. JSP. EJB和API等技术作了介绍, 适合具有一定编程基础的Java程序员阅读参考.
《J2EE核心模式》是Sun Java Center的资深设计师的J2EE亲身实践经验的总结. 该书主要描述J2EE关键技术(Java Server Pages, Java Servlet, Enterprise Java Beans, Java Message Services等)的模式. 最佳实践. 设计策略和经过验证的解决方案. 该书介绍了J2EE包括的15个模式的分类和大量的策略, 不仅具有理论深度, 而且非常实用. 该书内容适合J2EE的爱好者. 程序员. 设计师. 开发者和技术管理者. 一句话, 该书适合于设计. 构建和开发J2EE平台应用的所有人.
XML是新一代文档的标准, Web页. 数据. 源码等等, 均可以用XML文档表示. 越来越多的程序员正在使用Java来处理XML文档. 《用Java处理XML》详细论述了如何使用Java来读写XML文档. 该书是目前最新和最全的Java处理XML技术的介绍, 包含内容超过1000页的关于SAX, DOM, JDOM, JAXP, TrAX, XPath, XSLT, SOAP等的讲解. 该书适合于使用Java读写XML文档的Java程序员. 其内容从基本概念到高级应用无所不包, 特别适合作为手册随时参考.
在《实时Java》中, 作为RTSJ专家组的成员之一, Dibble从Java平台特有的实时问题概述开始, 依次讲解了RTSJ各项主要特性的使用方法. 从广泛的实时原理到详细的编程隐患, 该书覆盖了构建有效实时程序所需的一切知识. 其主要内容包括:与非实时代码的互操作性. 实时开发中的取舍以及JVM软件的实时问题, 垃圾收集. 无堆栈访问. 物理内存和“不朽”内存以及无堆栈内存的常数时间分配, 优先级调度. 期限调度以及速率单调分析, 闭包. 异步传输控制. 异步事件以及计时器. 这是一本非常实用的指南, 适用于有经验的Java平台开发人员.
《Java数据结构与算法分析》介绍了常见的数据结构, 如链表. 堆栈. 队列. 树和哈希表等, 并对查找和排序进行了算法分析, 给出了相应的Java实现. 该书逻辑结构严谨, 主次分明, 可用作程序员参考书.
总之, 这套书详细介绍了Java应用的许多重要方面: 从具有普遍性的Java数据结构和算法. Java设计模式. Java模式应用. J2EE核心模式, 到日益显著的Java特殊应用领域(Java处理XML文档和Java实时系统开发). 其内容具有一定的理论深度, 更有重要的实际参考价值.
有鉴于此, 特向Java系统开发和应用领域中不同程度的读者推荐这套书, 相信每位有心的读者都能得到物超所值的收获.
清华大学经济管理学院管理科学与工程系 朱涛 博士
讲授课程:Java程序设计, 面向对象的分析设计方法