- 浏览: 29127 次
- 性别:
- 来自: 厦门
-
文章分类
最新评论
-
gentlesong88:
赞一个 基础的操作都有了
条形码/二维码之开源利器ZXing图文介绍(转) -
苇间风语:
...
条形码/二维码之开源利器ZXing图文介绍(转) -
songfantasy:
学习了,今天刚好遇到这样的困惑。3Q
将变量置入循环
Creational patterns
Abstract factory (recognizeable by creational methods returning an abstract/interface type)
-
java.util.Calendar#getInstance()
-
java.util.Arrays#asList()
-
java.util.ResourceBundle#getBundle()
-
java.net.URL#openConnection()
-
java.sql.DriverManager#getConnection()
-
java.sql.Connection#createStatement()
-
java.sql.Statement#executeQuery()
-
java.text.NumberFormat#getInstance()
-
java.lang.management.ManagementFactory
(allgetXXX()
methods) -
java.nio.charset.Charset#forName()
-
javax.xml.parsers.DocumentBuilderFactory#newInstance()
-
javax.xml.transform.TransformerFactory#newInstance()
-
javax.xml.xpath.XPathFactory#newInstance()
-
java.net.URLStreamHandlerFactory#createURLStreamHandler(String)
(Returns singleton object per protocol)
Builder (recognizeable by creational methods returning the instance itself)
-
java.lang.StringBuilder#append()
(unsynchronized) -
java.lang.StringBuffer#append()
(synchronized) -
java.nio.ByteBuffer#put()
(also onCharBuffer
,ShortBuffer
,IntBuffer
,LongBuffer
,FloatBuffer
andDoubleBuffer
) -
javax.swing.GroupLayout.Group#addComponent()
- All implementations of
java.lang.Appendable
Factory method (recognizeable by creational methods returning a concrete type)
-
java.lang.Object#toString()
(overrideable in all subclasses) -
java.lang.Class#newInstance()
-
java.lang.Integer#valueOf(String)
(also onBoolean
,Byte
,Character
,Short
,Long
,Float
andDouble
) -
java.lang.Class#forName()
-
java.lang.reflect.Array#newInstance()
-
java.lang.reflect.Constructor#newInstance()
Prototype (recognizeable by creational methods returning a different instance of itself with the same properties)
-
java.lang.Object#clone()
(the class has to implementjava.lang.Cloneable
)
Singleton (recognizeable by creational methods returning the same instance (usually of itself) everytime)
Structural patterns
Adapter (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)
-
java.io.InputStreamReader(InputStream)
(returns aReader
) -
java.io.OutputStreamWriter(OutputStream)
(returns aWriter
) -
javax.xml.bind.annotation.adapters.XmlAdapter#marshal()
and#unmarshal()
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)
- None comes to mind yet. A fictive example would be
new LinkedHashMap(LinkedHashSet<K>, List<V>)
which returns an unmodifiable linked map which doesn't clone the items, but uses them. Thejava.util.Collections#newSetFromMap()
andsingletonXXX()
methods however comes close.
Composite (recognizeable by behavioral methods taking an instance of same abstract/interface type into a tree structure)
-
java.awt.Container#add(Component)
(practically all over Swing thus) -
javax.faces.component.UIComponent#getChildren()
(practically all over JSF UI thus)
Decorator (recognizeable by creational methods taking an instance of same abstract/interface type which adds additional behaviour)
- All subclasses of
java.io.InputStream
,OutputStream
,Reader
andWriter
have a constructor taking an instance of same type. -
java.util.Collections
, thecheckedXXX()
,synchronizedXXX()
andunmodifiableXXX()
methods. -
javax.servlet.http.HttpServletRequestWrapper
andHttpServletResponseWrapper
Facade (recognizeable by behavioral methods which internally uses instances of different independent abstract/interface types)
-
javax.faces.context.FacesContext
, it internally uses among others the abstract/interface typesLifeCycle
,ViewHandler
,NavigationHandler
and many more without that the enduser has to worry about it (which are however overrideable by injection). -
javax.faces.context.ExternalContext
, which internally usesServletContext
,HttpSession
,HttpServletRequest
,HttpServletResponse
, etc.
Flyweight (recognizeable by creational methods returning a cached instance, a bit the "multiton" idea)
-
java.lang.Integer#valueOf(int)
(also onBoolean
,Byte
,Character
,Short
,Long
,Float
andDouble
)
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)
-
java.lang.reflect.Proxy
-
java.rmi.*
, the whole API actually.
The Wikipedia example is IMHO a bit poor, lazy loading has actually completely nothing to do with the proxy pattern at all.
Behavioral patterns
Chain of responsibility (recognizeable by behavioral methods which (indirectly) invokes the same method in another 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)
- All implementations of
java.lang.Runnable
- All implementations of
javax.swing.Action
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)
-
java.util.Pattern
-
java.text.Normalizer
- All subclasses of
java.text.Format
- All subclasses of
javax.el.ELResolver
Iterator (recognizeable by behavioral methods sequentially returning instances of a different type from a queue)
- All implementations of
java.util.Iterator
(thus among others alsojava.util.Scanner
!). - All implementations of
java.util.Enumeration
Mediator (recognizeable by behavioral methods taking an instance of different abstract/interface type (usually using the command pattern) which delegates/uses the given instance)
-
java.util.Timer
(allscheduleXXX()
methods) -
java.util.concurrent.Executor#execute()
-
java.util.concurrent.ExecutorService
(theinvokeXXX()
andsubmit()
methods) -
java.util.concurrent.ScheduledExecutorService
(allscheduleXXX()
methods) -
java.lang.reflect.Method#invoke()
Memento (recognizeable by behavioral methods which internally changes the state of the whole instance)
-
java.util.Date
(the setter methods do that,Date
is internally represented by along
value) - All implementations of
java.io.Serializable
- All implementations of
javax.faces.component.StateHolder
Observer (or Publish/Subscribe) (recognizeable by behavioral methods which invokes a method on an instance of another abstract/interface type, depending on own state)
-
java.util.Observer
/java.util.Observable
(rarely used in real world though) - All implementations of
java.util.EventListener
(practically all over Swing thus) -
javax.servlet.http.HttpSessionBindingListener
-
javax.servlet.http.HttpSessionAttributeListener
-
javax.faces.event.PhaseListener
State (recognizeable by behavioral methods which changes its behaviour depending on the instance's state which can be controlled externally)
-
javax.faces.lifecycle.LifeCycle#execute()
(controlled byFacesServlet
, the behaviour is dependent on current phase (state) of JSF lifecycle)
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)
-
java.util.Comparator#compare()
, executed by among othersCollections#sort()
. -
javax.servlet.http.HttpServlet
, theservice()
and alldoXXX()
methods takeHttpServletRequest
andHttpServletResponse
and the implementor has to process them (and not to get hold of them as instance variables!). -
javax.servlet.Filter#doFilter()
Template method (recognizeable by behavioral methods which already have a "default" behaviour definied by an abstract type)
- All non-abstract methods of
java.io.InputStream
,java.io.OutputStream
,java.io.Reader
andjava.io.Writer
. - All non-abstract methods of
java.util.AbstractList
,java.util.AbstractSet
andjava.util.AbstractMap
. -
javax.servlet.http.HttpServlet
, all thedoXXX()
methods by default sends a HTTP 405 "Method Not Allowed" error to the response. You're free to implement none or any of them.
Visitor (recognizeable by two different abstract/interface types which has methods definied which takes each the other abstract/interface type; the one actually calls the method of the other and the other executes the desired strategy on it)
-
javax.lang.model.element.AnnotationValue
andAnnotationValueVisitor
-
javax.lang.model.element.Element
andElementVisitor
-
javax.lang.model.type.TypeMirror
andTypeVisitor
发表评论
-
顶级、块级、内联,html元素的三大分类
2012-09-14 13:57 576学习html后, 你会了解一些基本的html元素(Elem ... -
览器响应时间
2012-08-21 22:34 0以下是一种用于计算浏览器响应时间的基本方法: 浏览器响应时 ... -
性能调优方法
2012-07-20 17:04 680一. 算法调优 过滤算法 哈希算法 ... -
单例模式(Singleton)
2012-06-15 14:17 505单例模式: 一.特点 1. 只 ... -
GUI应用的若干问题和模式
2012-05-24 12:40 564摘选(http://www.infoq.com/cn/ar ... -
关于图像大小和分辨率
2011-03-09 09:31 778为了制作出高质量的图像,了解如何度量和显示图像的像素数据是非 ...
相关推荐
### JAVA设计模式在JDK中的应用 #### 一、引言 在软件开发过程中,设计模式作为一套被广泛接受的解决方案,能够帮助开发者解决常见的设计问题。Java作为一门流行的编程语言,其标准库(JDK)中巧妙地融入了多种设计...
### JDK中的设计模式 设计模式是在软件开发过程中总结出来的最佳实践,它们可以帮助开发者解决常见的问题并提高代码的可维护性和可扩展性。Java Development Kit (JDK) 中包含了许多设计模式的应用实例,这些实例...
JDK 中的 23 个设计模式简介 在 Java 开发领域,设计模式是一个非常重要的概念,它能够帮助开发者写出更加灵活、可维护、可扩展的代码。JDK 中也提供了许多设计模式的实现,本文将对其中的 23 个经典设计模式进行...
【设计模式概述】 设计模式是软件工程中经过实践...学习JDK中的设计模式可以让我们更好地理解Java库的设计思想,提升编程技巧,同时也能帮助我们更有效地运用这些模式到自己的项目中,编写出高质量、易于维护的代码。
设计模式在JDK中的应用课设--PPT资源 题目要求: 设计模式在JDK中的应用(结合JDK源码,分析JDK对设计模式的支持与应用)。课设内容包括: (a)用UML类图分析JDK所支持或应用的设计模式的结构,并与GOF的结构加以...
设计模式在JDK中的应用课设完整报告,Word文档 题目要求: 设计模式在JDK中的应用(结合JDK源码,分析JDK对设计模式的支持与应用)。课设内容包括: (a)用UML类图分析JDK所支持或应用的设计模式的结构,并与GOF的...
本资源主要围绕“设计模式实战”与“JDK源码解读”展开,帮助我们深入理解并运用设计模式,提升代码质量与可维护性。 首先,我们要明白设计模式的分类。设计模式分为三大类:创建型模式(如单例模式、工厂方法模式...
这些模式被广泛应用于Java等面向对象语言中,JDK(Java Development Kit)本身就是一个很好的实践场所,因为它包含了大量使用这些设计模式的例子。下面我们将详细探讨JDK中的23个设计模式及其应用。 1. 单例模式...
│ 3.1江湖传言里的设计模式-单例设计模式.mp4 │ 3.2代码实战-单例设计模式中的懒汉实现方式.mp4 │ 3.4单例模式中的饿汉实现和选择问题.mp4 │ 3.5JDK源码里面的单例设计模式.mp4 │ 4.2电商支付应用案例-...
介绍java二十三种设计模式,包括模式的描述,适用性,模式的组成部分,并附带有简单的例子和类图,目的是为了让读者了解二十三种设计模式,并能方便的查阅各种设计模式的用法及注意点,希望对大家有所帮助。...
本主题将深入探讨JDK中的重要工具、JVM(Java Virtual Machine)的垃圾回收机制以及23种经典的设计模式。 首先,JDK工具介绍: 1. `javac`:这是Java的编译器,用于将源代码编译成可执行的字节码。 2. `java`:这个...
day40 设计模式、jdk8新特性
JDK中许多类和方法都使用了设计模式,这些模式的应用帮助实现了代码的高内聚、低耦合,提高了代码的可维护性和扩展性。下面介绍几种常见的设计模式及其在JDK中的应用实例: a) 抽象工厂模式(AbstractFactory) ...
java常用设计模式及JDK与CGLIB实现动态代理区别(源码) /** * 使用cglib动态代理 * @author * */ public class BookFacadeProxy implements MethodInterceptor{ private Object target; @Override public...
虽然JDK 9才正式引入模块系统,但JDK 8的开发过程中已经开始了模块化的设计工作,为后续版本的模块化奠定了基础。 以上就是关于JDK 1.8.0_211的主要特性介绍。这个版本的JDK带来了许多重要的更新,极大地提升了Java...
JDK 8的Optional类也是一个重要的设计模式,它帮助解决null引用的问题,鼓励更清晰的代码结构。Optional对象表示可能为null的值,通过`isPresent()`、`get()`、`orElse()`等方法,可以避免空指针异常,使代码更具...
在这个场景中,我们关注的是JDK 8的RPM安装包,这是一种专为使用Red Hat Package Manager (RPM)的Linux发行版设计的软件包格式。 **一、JDK的组成部分** 1. **Java编译器** (javac):将源代码编译成可执行的字节码...