Examples of GoF Design Patterns--摘录
http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns
|
You can find an overview of a lot of design patterns in Wikipedia. It also mentions which patterns are mentioned by GoF. I'll sum them up here and try to assign as much as possible pattern implementations found in both the Java SE and Java EE API's. Creational patternsAbstract factory (recognizeable by creational methods returning the factory itself which in turn can be used to create another abstract/interface type)
Builder (recognizeable by creational methods returning the instance itself)
Factory method (recognizeable by creational methods returning an implementation of an abstract/interface type)
Prototype (recognizeable by creational methods returning a different instance of itself with the same properties)
Singleton (recognizeable by creational methods returning the same instance (usually of itself) everytime)Structural patternsAdapter (recognizeable by creational methods taking an instance of different abstract/interface type and returning an implementation of own/another abstract/interface type which decorates/overrides the given instance)
Bridge (recognizeable by creational methods taking an instance of different abstract/interface type and returning an implementation of own abstract/interface type which delegates/uses the given instance)
Composite (recognizeable by behavioral methods taking an instance of same abstract/interface type into a tree structure)
Decorator (recognizeable by creational methods taking an instance of same abstract/interface type which adds additional behaviour)
Facade (recognizeable by behavioral methods which internally uses instances of different independent abstract/interface types)
Flyweight (recognizeable by creational methods returning a cached instance, a bit the "multiton" idea)Proxy (recognizeable by creational methods which returns an implementation of given abstract/interface type which in turn delegates/uses a different implementation of given abstract/interface type)
The Wikipedia example is IMHO a bit poor, lazy loading has actually completely nothing to do with the proxy pattern at all. Behavioral patternsChain of responsibility (recognizeable by behavioral methods which (indirectly) invokes the same method inanother implementation of same abstract/interface type in a queue)Command (recognizeable by behavioral methods in an abstract/interface type which invokes a method in an implementation of a different abstract/interface type which has been encapsulated by the command implementation during its creation)
Interpreter (recognizeable by behavioral methods returning a structurally different instance/type of the given instance/type; note that parsing/formatting is not part of the pattern, determining the pattern and how to apply it is)
Iterator (recognizeable by behavioral methods sequentially returning instances of a different type from a queue)
Mediator (recognizeable by behavioral methods taking an instance of different abstract/interface type (usually using the command pattern) which delegates/uses the given instance)
Memento (recognizeable by behavioral methods which internally changes the state of the whole instance)
Observer (or Publish/Subscribe) (recognizeable by behavioral methods which invokes a method on an instance of another abstract/interface type, depending on own state)
State (recognizeable by behavioral methods which changes its behaviour depending on the instance's state which can be controlled externally)
Strategy (recognizeable by behavioral methods in an abstract/interface type which invokes a method in an implementation of a different abstract/interface type which has been passed-in as method argument into the strategy implementation)
Template method (recognizeable by behavioral methods which already have a "default" behaviour definied by an abstract type)
Visitor (recognizeable by two different abstract/interface types which has methods definied which takes each theother abstract/interface type; the one actually calls the method of the other and the other executes the desired strategy on it)
|
Examples of GoF Design Patterns--摘录的更多相关文章
- Examples of GoF Design Patterns in Java's core libraries
设计模式分类 stackOverflow Structural(结构模式) Adapter:把一个接口或是类变成另外一种. java.util.Arrays#asList() javax.swing. ...
- UML系列,使用UML实现GOF Design patterns,常用模式类图解读
1.单例:Singleton, DirectedAssociation
- Design Patterns Example Code (in C++)
Overview Design patterns are ways to reuse design solutions that other software developers have crea ...
- How I explained Design Patterns to my wife: Part 1
Introduction Me and my wife had some interesting conversations on Object Oriented Design principles. ...
- Learning JavaScript Design Patterns The Observer Pattern
The Observer Pattern The Observer is a design pattern where an object (known as a subject) maintains ...
- Learning JavaScript Design Patterns The Module Pattern
The Module Pattern Modules Modules are an integral piece of any robust application's architecture an ...
- MapReduce Design Patterns(chapter 1)(一)
Chapter 1.Design Patterns and MapReduce MapReduce 是一种运行于成百上千台机器上的处理数据的框架,目前被google,Hadoop等多家公司或社区广泛使 ...
- (转)MapReduce Design Patterns(chapter 1)(一)
翻译的是这本书: Chapter 1.Design Patterns and MapReduce MapReduce 是一种运行于成百上千台机器上的处理数据的框架,目前被google,Hadoop等多 ...
- AMD - Learning JavaScript Design Patterns [Book] - O'Reilly
AMD - Learning JavaScript Design Patterns [Book] - O'Reilly The overall goal for the Asynchronous Mo ...
随机推荐
- 手动编译安装lamp之mysql
转自马哥教育的讲课文档 二.安装mysql-5.5.28 1.准备数据存放的文件系统 新建一个逻辑卷,并将其挂载至特定目录即可.这里不再给出过程. 这里假设其逻辑卷的挂载目录为/mydata,而后需要 ...
- DOORS的引用类型
DOORS的引用类型包括:Project: 项目引用Folder: 文件夹引用Item: 项目或文件夹之内的项(项目.文件夹.模块)Module: 打开模块的引用Object: 对象的引用 ...
- WPF 使用QRCoder生成二维码
vs中使用Nuget获取QRCoder 窗体中添加按钮和Iage <Window x:Class="QRCoderTest.MainWindow" xmlns="h ...
- bat windows10系统垃圾清理---
@echo off color 0a title windows10系统垃圾清理--- echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★ echo ★☆ ★☆ ★☆ ★☆ ★☆ ...
- ANE-如何加入ane,调试时又不报错
有时候我们加入ane,即使没有调用ane的功能,debug的时候也会报错无法调试,这是为什么呢?因为我们的ane没有把default包含进去. 首先我们的extension.xml要把default节 ...
- linux 使用内存作为 /tmp 临时文件夹
方法一:cat /etc/fstabtmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0 方法二:mount tmpfs /tmp -t tmpfs -o s ...
- MySql数据库备份的几种方式
mysqldump工具备份 备份整个数据库 $> mysqldump -u root -h host -p dbname > backdb.sql 备份数据库中的某个表 $> mys ...
- 【vue】——CDN或全局引入CSS、JS。
在入口文件index.html中添加 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Java 读写锁的实现
一. synchronized和ReentrantLock的对比 到现在,看到多线程中,锁定的方式有2种:synchronized和ReentrantLock.两种锁定方式各有优劣,下面简单对比 ...
- Java最常见的200+面试题及自己梳理的答案--面试必备(一)
昨天在今日头条上看到一份所谓经常面别人的TL梳理的面试题,看着比较完善,但是,没有对应的答案,自己看着研究学习了下,顺带梳理下答案.主要包括以下模块:Java基础.容器.多线程.反射.对象拷贝.Jav ...