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 ...
随机推荐
- 使用 Build Pipeline View 插件图表展示Jenkins job依赖关系
使用 Build Pipeline View 查看Jenkins的Job的依赖关系图表 安装 Build Pipeline View 插件下载地址 下载后再jenkins的"插件管理&quo ...
- ZENCART 菜鸟找人一起学习
ZENCART 是一个很强大的外贸CMS程序. 现在刚开始学习,虽然晚了五年…… 有兴趣的朋友加群一起学习交流吧 学习论坛: http://www.zencart-bbs.com/thread-htm ...
- Spring Data MongoDB 一:入门篇(环境搭建、简单的CRUD操作)
一.简介 Spring Data MongoDB 项目提供与MongoDB文档数据库的集成.Spring Data MongoDB POJO的关键功能区域为中心的模型与MongoDB的DBColle ...
- python文件备份与简单操作
#!/usr/bin/python # -*- coding: utf-8 -*- # data:2018/8/30 # user:fei import sys import random num = ...
- Elasticsearch学习(4) spring boot整合Elasticsearch的聚合操作
之前已将spring boot原生方式介绍了,接下将结介绍的是Elasticsearch聚合操作.聚合操作一般来说是解决一下复杂的业务,比如mysql中的求和和分组,由于博主踩的坑比较多,所以博客可能 ...
- 【OCP 12c】最新CUUG OCP-071考试题库(61题)
61.(18-6) choose the best answer: View the Exhibit and examine the structure of the CUSTOMERS table. ...
- “全栈2019”Java多线程第十一章:线程优先级详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- 小A的旅行(绿豆蛙的归宿)【期望DP】
Description 给出一个有向无环的连通图,起点为1,终点为N,每条边都有一个长度.小A从起点出发,走向终点.到达每一个顶点时,如果有K条离开该点的道路,小A可以选择任意一条道路离开该点,并且走 ...
- Python面向对象(构造方法)
day24 构造方法 特殊作用:在obj=classname()中1.创建对象,2.通过对象执行类中的一个特殊方法. class Bar: def __init__(self): ") de ...
- Python面向对象(self参数、封装)
day24 面向对象三大特性:封装 self参数 class Bar: def foo(self, arg): print(self, arg) x = Bar() print(x) x.foo(11 ...