The Chain of Responsibility Pattern is a design pattern whose intent is to avoid coupling the sender of a request to its receivers by giving more than one object a chance to handle a request. The Chain of Responsibility works like this:
Summary: A Java "extract method" refactoring example is demonstrated.
If you don't own a copy of Martin Fowler's Refactoring book, I highly recommend it. The basic idea of refactoring source code is that the code "smells" in one way or another, and there are a variety of ways to improve smelly code. More specifically, Mr. Fowler describes refactoring as this:
Java FAQ: Can you share some examples of common Java regular expressions?
The following list shows some of the most common regular expressions that are used in computer programming. I haven’t tested any of these yet with Java, but I think most will work off the shelf, or should at least work with minor tweaks.
An interesting note is that there are several ways to write the same regular expression, and I intentionally tried to stress that in the examples below.
For a Perl program that I'm working on right now, I need to match the elements of an array of strings against several patterns, and then take an action if the current string matches one of my patterns. This is pretty easy in this case, in part because it's easy to match a string against multiple patterns in Perl, and also because my patterns are very simple -- no regular expressions involved.
I have used GRASP in one context in this blog, but the GRASP I'm interested in today refers to Craig Larman's General Responsibility and Assignment Patterns. I saw those first referenced in Larman's book titled "Applying UML and Patterns". Larman's home page is one big page, but what the heck, he's a good author.