更新时间:2022-09-17 10:22:11
参考1:http://***.com/questions/1673841/examples-of-gof-design-patterns
参考2:http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
参考3:http://zh.wikipedia.org/wiki/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_(%E8%AE%A1%E7%AE%97%E6%9C%BA)
You can find an overview of a lot 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.
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
(all getXXX()
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)java.lang.StringBuilder#append()
(unsynchronized)java.lang.StringBuffer#append()
(synchronized)java.nio.ByteBuffer#put()
(also on CharBuffer
, ShortBuffer
, IntBuffer
, LongBuffer
,FloatBuffer
and DoubleBuffer
)javax.swing.GroupLayout.Group#addComponent()
java.lang.Appendable
java.lang.Object#toString()
(overrideable in all subclasses)java.lang.Class#newInstance()
java.lang.Integer#valueOf(String)
(also on Boolean
, Byte
, Character
, Short
, Long
,Float
and Double
)java.lang.Class#forName()
java.lang.reflect.Array#newInstance()
java.lang.reflect.Constructor#newInstance()
java.lang.Object#clone()
(the class has to implement java.lang.Cloneable
)java.io.InputStreamReader(InputStream)
(returns a Reader
)java.io.OutputStreamWriter(OutputStream)
(returns a Writer
)javax.xml.bind.annotation.adapters.XmlAdapter#marshal()
and #unmarshal()
new LinkedHashMap(LinkedHashSet<K>, List<V>)
which returns an unmodifiable linked map which doesn't clone the items, but uses them. The java.util.Collections#newSetFromMap()
and singletonXXX()
methods however comes close.java.util.Map#putAll(Map)
java.util.List#addAll(Collection)
java.util.Set#addAll(Collection)
java.nio.ByteBuffer#put(ByteBuffer)
(also on CharBuffer
, ShortBuffer
, IntBuffer
,LongBuffer
, FloatBuffer
and DoubleBuffer
)java.awt.Container#add(Component)
(practically all over Swing thus)java.io.InputStream
, OutputStream
, Reader
and Writer
have a constructor taking an instance of same type.java.util.List
, Set
and Map
have a constructor taking an instance of same type.java.util.Collections
, the checkedXXX()
, synchronizedXXX()
and unmodifiableXXX()
methods.javax.servlet.http.HttpServletRequestWrapper
and HttpServletResponseWrapper
javax.faces.context.FacesContext
, it internally uses among others the abstract/interface types LifeCycle
, 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 uses ServletContext
,HttpSession
, HttpServletRequest
, HttpServletResponse
, etc.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.
java.lang.Runnable
javax.swing.Action
java.util.Pattern
java.text.Normalizer
java.text.Format
javax.el.ELResolver
java.util.Iterator
(thus among others also java.util.Scanner
!).java.util.Enumeration
java.util.Timer
(all scheduleXXX()
methods)java.util.concurrent.Executor#execute()
java.util.concurrent.ExecutorService
(the invokeXXX()
and submit()
methods)java.util.concurrent.ScheduledExecutorService
(all scheduleXXX()
methods)java.lang.reflect.Method#invoke()
java.util.Date
(the setter methods do that, Date
is internally represented by a long
value)java.io.Serializable
javax.faces.component.StateHolder
java.util.Observer
/java.util.Observable
(rarely used in real world though)java.util.EventListener
(practically all over Swing thus)javax.servlet.http.HttpSessionBindingListener
javax.servlet.http.HttpSessionAttributeListener
javax.faces.event.PhaseListener
javax.faces.lifecycle.LifeCycle#execute()
(controlled by FacesServlet
, the behaviour is dependent on current phase (state) of JSF lifecycle)java.util.Comparator#compare()
, executed by among others Collections#sort()
.javax.servlet.http.HttpServlet
, the service()
and all doXXX()
methods takeHttpServletRequest
and HttpServletResponse
and the implementor has to process them (and not to get hold of them as instance variables!).javax.servlet.Filter#doFilter()
java.io.InputStream
, java.io.OutputStream
, java.io.Reader
and java.io.Writer
.java.util.AbstractList
, java.util.AbstractSet
andjava.util.AbstractMap
.javax.servlet.http.HttpServlet
, all the doXXX()
methods by default sends a HTTP 405 "Method Not Allowed" error to the response. You're free to implement none or any of them.javax.lang.model.element.AnnotationValue
and AnnotationValueVisitor
javax.lang.model.element.Element
and ElementVisitor
javax.lang.model.type.TypeMirror
and TypeVisitor