"1 in 10 cant even pass a simple test like ‘which design pattern is used in the streams library that makes BufferedFileReader interchangeable with a FileReader?'"
Adapter:
This is used to convert the programming interface/class into that of another.
-java.util.Arrays#asList()
-javax.swing.JTable(TableModel)
-java.io.InputStreamReader(InputStream)
-java.io.OutputStreamWriter(OutputStream)
-javax.xml.bind.annotation.adapters.XmlAdapter#marshal()
-javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal()
Bridge:
This decouples an abstraction from the implementation of its abstract operations, so that the abstraction and its implementation can vary independently.
-AWT (It provides an abstraction layer which maps onto the native OS the windowing support.)
-JDBC
Composite:
Lets clients treat individual objects and compositions of objects uniformly. So in other words methods on a type accepting the same type.
-javax.swing.JComponent#add(Component)
-java.awt.Container#add(Component)
-java.util.Map#putAll(Map)
-java.util.List#addAll(Collection)
-java.util.Set#addAll(Collection)
Decorator:
Attach additional responsibilities to an object dynamically and therefore it is also an alternative to subclassing. Can be seen when creating a type passes in the same type.
-java.io.BufferedInputStream(InputStream)
-java.io.DataInputStream(InputStream)
-java.io.BufferedOutputStream(OutputStream)
-java.util.zip.ZipOutputStream(OutputStream)
-java.util.Collections.unmodifiableCollection|synchronizedCollection
Collections.checkedCollection
Returns a dynamically typesafe view of the specified collection. Any attempt to insert an element of the wrong type will result in an immediate ClassCastException.
#checked[List|Map|Set|SortedSet|SortedMap]()
Facade:
To provide a simplified interface to a group of components, interfaces, abstractions or subsystems.
-java.lang.Class
-javax.faces.webapp.FacesServlet
Flyweight:
Caching to support large numbers of smaller objects efficiently. I stumbled apon this a couple months back.
-java.lang.Integer#valueOf(int)
-java.lang.Boolean#valueOf(boolean)
-java.lang.Byte#valueOf(byte)
-java.lang.Character#valueOf(char)
Proxy:
The Proxy pattern is used to represent with a simpler object an object that is complex or time consuming to create.
-java.lang.reflect.Proxy
-RMI
Creational
Abstract factory:
To provide a contract for creating families of related or dependent objects without having to specify their concrete classes. It enables one to decouple an application from the concrete implementation of an entire framework one is using. This is also found all over the JDK and a lot of frameworks like Spring. They are simple to spot, any method that is used to create an object but still returns a interface or abstract class.
-java.util.Calendar#getInstance()
-java.util.Arrays#asList()
-java.util.ResourceBundle#getBundle()
-java.sql.DriverManager#getConnection()
-java.sql.Connection#createStatement()
-java.sql.Statement#executeQuery()
-java.text.NumberFormat#getInstance()
-javax.xml.transform.TransformerFactory#newInstance()
Builder:
Used simplify complex object creation by defining a class whose purpose is to build instances of another class. The builder pattern also allows for the implementation of a Fluent Interface.
-java.lang.StringBuilder#append()
-java.lang.StringBuffer#append()
-java.sql.PreparedStatement
-javax.swing.GroupLayout.Group#addComponent()
Factory method:
Simply a method that returns an actual type.
-java.lang.Proxy#newProxyInstance()
-java.lang.Object#toString()
-java.lang.Class#newInstance()
-java.lang.reflect.Array#newInstance()
-java.lang.reflect.Constructor#newInstance()
-java.lang.Boolean#valueOf(String)
-java.lang.Class#forName()
Prototype:
Allows for classes whose instances can create duplicates of themselves. This can be used when creating an instance of a class is very time-consuming or complex in some way, rather than creating new instances, you can make copies of the original instance and modify it.
-java.lang.Object#clone()
-java.lang.Cloneable
Singleton:
This tries to ensure that there is only a single instance of a class. I didn't find an example but another solution would be to use an Enum as Joshua Bloch suggests in Effective Java.
-java.lang.Runtime#getRuntime()
-java.awt.Toolkit#getDefaultToolkit()
-java.awt.GraphicsEnvironment#getLocalGraphicsEnvironment()
-java.awt.Desktop#getDesktop()
Behavioral
Chain of responsibility:
Allows for the decoupling between objects by passing a request from one object to the next in a chain until the request is recognized. The objects in the chain are different implementations of the same interface or abstract class.
-java.util.logging.Logger#log()
-javax.servlet.Filter#doFilter()
Command:
To wrap a command in an object so that it can be stored, passed into methods, and returned like any other object.
-java.lang.Runnable
-javax.swing.Action
Interpreter:
This pattern generally describes defining a grammar for that language and using that grammar to interpret statements in that format.
-java.util.Pattern
-java.text.Normalizer
-java.text.Format
Iterator:
To provide a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection.
-java.util.Iterator
-java.util.Enumeration
Mediator:
Used to reduce the number of direct dependencies between classes by introducing a single object that manages message distribution.
-java.util.Timer
-java.util.concurrent.Executor#execute()
-java.util.concurrent.ExecutorService#submit()
-java.lang.reflect.Method#invoke()
Memento:
This is a snapshot of an object’s state, so that the object can return to its original state without having to reveal it's content. Date does this by actually having a long value internally.
-java.util.Date
-java.io.Serializable
Null Object:
This can be used encapsulate the absence of an object by providing an alternative 'do nothing' behavior. It allows you to abstract the handling of null objects.
-java.util.Collections#emptyList()
-java.util.Collections#emptyMap()
-java.util.Collections#emptySet()
Observer:
Used to provide a way for a component to flexibly broadcast messages to interested receivers.
-java.util.EventListener
-javax.servlet.http.HttpSessionBindingListener
-javax.servlet.http.HttpSessionAttributeListener
-javax.faces.event.PhaseListener
State:
This allows you easily change an object’s behavior at runtime based on internal state.
-java.util.Iterator
-javax.faces.lifecycle.LifeCycle#execute()
Strategy:
Is intended to provide a means to define a family of algorithms, encapsulate each one as an object. These can then be flexibly passed in to change the functionality.
-java.util.Comparator#compare()
-javax.servlet.http.HttpServlet
-javax.servlet.Filter#doFilter()
Template method:
Allows subclasses to override parts of the method without rewriting it, also allows you to control which operations subclasses are required to override.
-java.util.Collections#sort()
-java.io.InputStream#skip()
-java.io.InputStream#read()
-java.util.AbstractList#indexOf()
Visitor:
To provide a maintainable, easy way to perform actions for a family of classes. Visitor centralizes the behaviors and allows them to be modified or extended without changing the classes they operate on.
-javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor
-javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor
Read full article from Zen in the art of IT: Design Patterns in the JDK.
Adapter:
This is used to convert the programming interface/class into that of another.
-java.util.Arrays#asList()
-javax.swing.JTable(TableModel)
-java.io.InputStreamReader(InputStream)
-java.io.OutputStreamWriter(OutputStream)
-javax.xml.bind.annotation.adapters.XmlAdapter#marshal()
-javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal()
Bridge:
This decouples an abstraction from the implementation of its abstract operations, so that the abstraction and its implementation can vary independently.
-AWT (It provides an abstraction layer which maps onto the native OS the windowing support.)
-JDBC
Composite:
Lets clients treat individual objects and compositions of objects uniformly. So in other words methods on a type accepting the same type.
-javax.swing.JComponent#add(Component)
-java.awt.Container#add(Component)
-java.util.Map#putAll(Map)
-java.util.List#addAll(Collection)
-java.util.Set#addAll(Collection)
Decorator:
Attach additional responsibilities to an object dynamically and therefore it is also an alternative to subclassing. Can be seen when creating a type passes in the same type.
-java.io.BufferedInputStream(InputStream)
-java.io.DataInputStream(InputStream)
-java.io.BufferedOutputStream(OutputStream)
-java.util.zip.ZipOutputStream(OutputStream)
-java.util.Collections.unmodifiableCollection|synchronizedCollection
Collections.checkedCollection
Returns a dynamically typesafe view of the specified collection. Any attempt to insert an element of the wrong type will result in an immediate ClassCastException.
#checked[List|Map|Set|SortedSet|SortedMap]()
Facade:
To provide a simplified interface to a group of components, interfaces, abstractions or subsystems.
-java.lang.Class
-javax.faces.webapp.FacesServlet
Flyweight:
Caching to support large numbers of smaller objects efficiently. I stumbled apon this a couple months back.
-java.lang.Integer#valueOf(int)
-java.lang.Boolean#valueOf(boolean)
-java.lang.Byte#valueOf(byte)
-java.lang.Character#valueOf(char)
Proxy:
The Proxy pattern is used to represent with a simpler object an object that is complex or time consuming to create.
-java.lang.reflect.Proxy
-RMI
Creational
Abstract factory:
To provide a contract for creating families of related or dependent objects without having to specify their concrete classes. It enables one to decouple an application from the concrete implementation of an entire framework one is using. This is also found all over the JDK and a lot of frameworks like Spring. They are simple to spot, any method that is used to create an object but still returns a interface or abstract class.
-java.util.Calendar#getInstance()
-java.util.Arrays#asList()
-java.util.ResourceBundle#getBundle()
-java.sql.DriverManager#getConnection()
-java.sql.Connection#createStatement()
-java.sql.Statement#executeQuery()
-java.text.NumberFormat#getInstance()
-javax.xml.transform.TransformerFactory#newInstance()
Builder:
Used simplify complex object creation by defining a class whose purpose is to build instances of another class. The builder pattern also allows for the implementation of a Fluent Interface.
-java.lang.StringBuilder#append()
-java.lang.StringBuffer#append()
-java.sql.PreparedStatement
-javax.swing.GroupLayout.Group#addComponent()
Factory method:
Simply a method that returns an actual type.
-java.lang.Proxy#newProxyInstance()
-java.lang.Object#toString()
-java.lang.Class#newInstance()
-java.lang.reflect.Array#newInstance()
-java.lang.reflect.Constructor#newInstance()
-java.lang.Boolean#valueOf(String)
-java.lang.Class#forName()
Prototype:
Allows for classes whose instances can create duplicates of themselves. This can be used when creating an instance of a class is very time-consuming or complex in some way, rather than creating new instances, you can make copies of the original instance and modify it.
-java.lang.Object#clone()
-java.lang.Cloneable
Singleton:
This tries to ensure that there is only a single instance of a class. I didn't find an example but another solution would be to use an Enum as Joshua Bloch suggests in Effective Java.
-java.lang.Runtime#getRuntime()
-java.awt.Toolkit#getDefaultToolkit()
-java.awt.GraphicsEnvironment#getLocalGraphicsEnvironment()
-java.awt.Desktop#getDesktop()
Behavioral
Chain of responsibility:
Allows for the decoupling between objects by passing a request from one object to the next in a chain until the request is recognized. The objects in the chain are different implementations of the same interface or abstract class.
-java.util.logging.Logger#log()
-javax.servlet.Filter#doFilter()
Command:
To wrap a command in an object so that it can be stored, passed into methods, and returned like any other object.
-java.lang.Runnable
-javax.swing.Action
Interpreter:
This pattern generally describes defining a grammar for that language and using that grammar to interpret statements in that format.
-java.util.Pattern
-java.text.Normalizer
-java.text.Format
Iterator:
To provide a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection.
-java.util.Iterator
-java.util.Enumeration
Mediator:
Used to reduce the number of direct dependencies between classes by introducing a single object that manages message distribution.
-java.util.Timer
-java.util.concurrent.Executor#execute()
-java.util.concurrent.ExecutorService#submit()
-java.lang.reflect.Method#invoke()
Memento:
This is a snapshot of an object’s state, so that the object can return to its original state without having to reveal it's content. Date does this by actually having a long value internally.
-java.util.Date
-java.io.Serializable
Null Object:
This can be used encapsulate the absence of an object by providing an alternative 'do nothing' behavior. It allows you to abstract the handling of null objects.
-java.util.Collections#emptyList()
-java.util.Collections#emptyMap()
-java.util.Collections#emptySet()
Observer:
Used to provide a way for a component to flexibly broadcast messages to interested receivers.
-java.util.EventListener
-javax.servlet.http.HttpSessionBindingListener
-javax.servlet.http.HttpSessionAttributeListener
-javax.faces.event.PhaseListener
State:
This allows you easily change an object’s behavior at runtime based on internal state.
-java.util.Iterator
-javax.faces.lifecycle.LifeCycle#execute()
Strategy:
Is intended to provide a means to define a family of algorithms, encapsulate each one as an object. These can then be flexibly passed in to change the functionality.
-java.util.Comparator#compare()
-javax.servlet.http.HttpServlet
-javax.servlet.Filter#doFilter()
Template method:
Allows subclasses to override parts of the method without rewriting it, also allows you to control which operations subclasses are required to override.
-java.util.Collections#sort()
-java.io.InputStream#skip()
-java.io.InputStream#read()
-java.util.AbstractList#indexOf()
Visitor:
To provide a maintainable, easy way to perform actions for a family of classes. Visitor centralizes the behaviors and allows them to be modified or extended without changing the classes they operate on.
-javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor
-javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor
Read full article from Zen in the art of IT: Design Patterns in the JDK.
Hello There,
ReplyDeleteGreat post. Well though out. This piece reminds me when I was starting out Zen in the art of IT: Design Patterns in the JDK after graduating from college.
This is Erin from Amazon Web Services. I took a look at the support case you provided, I see that one of our agents was able to assist and resolve the case.
Please let us know if there is anything else we can help with!
Awesome! Thanks for putting this all in one place. Very useful!
Kind Regards,
Abhiram
Salama Aleikum,
ReplyDeleteThis is indeed great! But I think perhaps you are Zen in the art of IT: Design Patterns in the JDK which is getting unsustainable.
As far as all my research has led me to conclude, AWS only has one service that supports websocket protocol for pushing data straight to browsers. SNS solely supports mobile. IoT supports websocket over MQTT, albeit awkwardly, requiring you to treat ephemeral browser sessions like devices. Some libraries to abstract this awkward fit have popped up.
Every time you launch an instance from an AMI, a root storage device is created for that instance. The root storage device contains all the information necessary to boot the instance. You can specify storage volumes in addition AWS Tutorial to the root device volume when you create an AMI or launch an instance using block device mapping.
Very useful post! everyone should learn and use it during their learning path.
Muchas Gracias,
Kevin
Salemetsiz Be,
ReplyDelete11/10!! Your blog is such a complete read. I like your approach with Zen in the art of IT: Design Patterns in the JDK. . Clearly, you wrote it to make learning a cake walk for me. AWS Training USA
I like the support for S3 in the AWS console, especially being able to apply ACLs at time of upload. However, it would be very good if the view was sortable by last modified date, as I am typically working with the last 10-15 files uploaded.
It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
Keep up the good work!
Cheers,
Radhey
Hi There,
ReplyDeleteThree cheers to you! Hooray!!! I feel like I hit the jackpot on Zen in the art of IT: Design Patterns in the JDK!
I logged into console.aws.amazon.com today and now every few seconds a popup says I need to reload (and re-login). This has happened before after a long time of inactivity, but now it's happening so often I can't look at anything without having to reload and login.
In Spot and On-demand instance, AWS Training USA there is no commitment for the duration from the user side, however in reserved instances, one has to stick to the time period that he has chosen.
THANK YOU!! This saved my butt today, I’m immensely grateful.
Obrigado,
Kevin
Bonjour,
ReplyDeleteI genuinely do look forward for the time where you post some new write ups. Your blog make me feel so educated! Continue soaring and writing please. AWS Tutorial
AWS should allow customers or give an option to publish CloudWatch dashboards publicly, and which means that whenever we create a CloudWatch dashboard we get a public EndPoint like we get in case of S3 buckets (e.g. static web site hosting). And then we can share the endpoint URL to access the CloudWatch dashboard with users inside or outside the organization without going into user/role creation hassle. Same endpoint url can be used to integrate or embed CloudWatch dashboard in enterprise applications.
THANK YOU!! This saved my butt today, I’m immensely grateful.
Thank you,
Radhey