Java Design Patterns for Reuse

本文所有栗子来源于老师课件

                                                              Structural patterns 结构型模式

(1)Adapter  适配器模式

将某个类/接口转换为client期望的其他形式

通过增加一个接口,将已存在的子类封装起来,client面向接口编程,从而隐藏了具体子类。


(2)Decorator 装饰器模式

为对象增加不同侧面的特性

为每一个特性构造子类,通过委派机制增加到对象上



(3)Facade 外观模式

客户端需要一个简化的接口访问复杂系统内的功能

提供一个统一的接口来取代一系列小接口的调用,相当于对复杂系统做了一个封装,简化客户端使用

                                                Behavioral patterns 行为类模式

(1) Strategy  策略模式

优点:易于扩展的新算法实现,将算法与客户端上下文分离


(2) Template Method 模板模式

 做事情的步骤一样,但具体方法不同。共性的步骤在抽象类内公共实现,差异化的步骤在各个子类中实现。使用继承和重写实现模板模式


(3) Iterator 迭代器模式

抽象迭代器类定义遍历协议
每个聚合类的具体迭代器子类
聚集实例创建迭代器对象的实例

聚集实例保持对迭代器对象的引用



总结:

Structural patterns 结构模式
Adapter:允许具有不兼容接口的类通过围绕已存在类的接口包装自己的接口来协同工作。
Decorator:在对象的现有方法中动态地添加/重写行为。
Facade:为大量代码提供一个简化的接口。


Behavioral patterns行为模式

Strategy:允许在运行时动态选择一个算法家族中的一个。
Template method:将算法的框架定义为一个抽象类,允许其子类提供具体的行为。
Iterator按顺序访问对象的元素,而不暴露其底层表示。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Learn how to implement design patterns in Java: each pattern in Java Design Patterns is a complete implementation and the output is generated using Eclipse, making the code accessible to all. The examples are chosen so you will be able to absorb the core concepts easily and quickly. This book presents the topic of design patterns in Java in such a way that anyone can grasp the idea. By giving easy to follow examples, you will understand the concepts with increasing depth. The examples presented are straightforward and the topic is presented in a concise manner. Key features of the book: Each of the 23 patterns is described with straightforward Java code. There is no need to know advanced concepts of Java to use this book. Each of the concepts is connected with a real world example and a computer world example. The book uses Eclipse IDE to generate the output because it is the most popular IDE in this field. This is a practitioner's book on design patterns in Java. Design patterns are a popular topic in software development. A design pattern is a common, well-described solution to a common software problem. There is a lot of written material available on design patterns, but scattered and not in one single reference source. Also, many of these examples are unnecessarily big and complex. Table of Contents Chapter 1: Introduction Chapter 2: Observer Patterns Chapter 3: Singleton Patterns Chapter 4: Proxy Patterns Chapter 5: Decorator Patterns Chapter 6: Template Method Patterns Chapter 7: Strategy Patterns (Or, Policy Patterns) Chapter 8: Adapter Patterns Chapter 9: Command Patterns Chapter 10: Iterator Patterns Chapter 11: Facade Patterns Chapter 12: Factory Method Patterns Chapter 13: Memento Patterns Chapter 14: State Patterns Chapter 15: Builder Patterns Chapter 16: Flyweight Patterns Chapter 17: Abstract Factory Patterns Chapter 18: Mediator Patterns Chapter 19: Prototype Patterns Chapter 20: Chain of Responsibility Patterns Chapter 21: Composite Patterns Chapter 22: Bridge Patterns (Or Handle/Body Patterns) Chapter 23: Visitor Patterns Chapter 24: Interpreter Patterns
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值