I saw an article (well more of a rant) the other day, by Rob Williams Brain Drain in enterprise Dev. I have to say, I do agree with some of what he is saying. I know from my personal experience, I had spent a good 2 or so years just wallowing in the enterprise development world, not learning anything and actually losing my skills I developed before. The corporate confront zone is not conducive to eager technologists.
In this article he also stated:
I also tested it at work and I only had 1 out of the 8 people asked that got it right
Without much confidence, I had guessed Decorator based on “interchangeable”. I then decided that was actually some worth sneaking into future interviews, and probably a good time to revise a little.
So I went scouring the internet to find all I could on the topic and I didn’t actually find as much as I thought I would. Most of it came from BalusC at Stackoverflow, the rest was very scattered between blog posts, java ranch, some old pdf’s and articles I had. I didn’t take every single example of every single pattern I found, but rather the common ones.
This may be a good way for people to learn about patterns, quite often they are using them everyday without realizing.
This is used to convert the programming interface/class into that of another.
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.)
Lets clients treat individual objects and compositions of objects uniformly. So in other words methods on a type accepting the same type.
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. This is actually used all over the JDK, the more you look the more you find, so the list below is definitely not complete.
To provide a simplified interface to a group of components, interfaces, abstractions or subsystems.
Caching to support large numbers of smaller objects efficiently. I stumbled apon this a couple months back.
The Proxy pattern is used to represent with a simpler object an object that is complex or time consuming to create.
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.
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.
Simply a method that returns an actual type.
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.
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.
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.
To wrap a command in an object so that it can be stored, passed into methods, and returned like any other object.
This pattern generally describes defining a grammar for that language and using that grammar to interpret statements in that format.
To provide a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection.
Used to reduce the number of direct dependencies between classes by introducing a single object that manages message distribution.
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.
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.
Used to provide a way for a component to flexibly broadcast messages to interested receivers.
This allows you easily change an object’s behavior at runtime based on internal state.
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.
Allows subclasses to override parts of the method without rewriting it, also allows you to control which operations subclasses are required to override.
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
Better is the enemy of good!
Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code
Use Java? If you do, you know that Java software can be used to drive application logic of Web services or Web applications. Perhaps you use it for desktop applications? Or, embedded devices? Whatever your use of Java code, functional errors are the enemy!
To combat this enemy, your team might already perform functional testing. Even so, you're taking significant risks if you have not yet implemented a comprehensive team-wide quality management strategy. Such a strategy alleviates reliability, security, and performance problems to ensure that your code is free of functionality errors.Read this article to learn about this simple four-step strategy that is proven to make Java code more reliable, more secure, and easier to maintain.