Skip to main content

New Article: The Match Maker Design Pattern - a New Place for the Actions

Posted by editor on April 27, 2010 at 5:41 AM PDT

We've just published Michael Bar-Sinai's new article, The Match Maker Design Pattern - a New Place for the Actions. In this article, Michael tackles some of the problems associated with object-oriented design within the context of the changing requirements that the real-life business world imposes on software applications over time. To see what I mean, here's Michael's opening paragraph:

Software systems often deal with similar concepts, whose behavior differs only slightly. Classic Object-Oriented design deals with such cases using inheritance; overriding the calculateSalary() method in different Employee subclasses allows the rest of the application to remain oblivious to the subtle differences between the salary algorithms of Manager, Engineer, and AnnoyingCeoNephew.

In the article, Michael presents a solution that, while not a "silver bullet", provides benefits that work in a majority of real-life cases where you're updating software applications to address changed business requirements. His section "Dealing With New Classes On The Fly" opens with:

A MatchMaker instance does hold a Map mapping classes to handlers, but with a twist. When it is given an instance of a class for which a handler was not explicitly specified, it embarks on a breadth-first search (BFS) up the class hierarchy, starting from that object's class, looking for a class for which a handler was explicitly specified. A property of BFS is that it ensures that the class found is the closest one to the original object's class. Note that there might be a few classes with the same distance.

Figure 1. Class hierarchy and handlers example.

The article contains plenty of code snippets that illustrate the match maker technique. Michael concludes the article with this summary:

We have seen the Match Maker pattern, which allows programmers to:

  • add actions on objects without modifying the objects those actions operate on;
  • add objects and have appropriate actions automatically operate on them; and
  • work on a subclass while holding only a superclass reference to it, without downcasting.

We have seen two implementations, one simple yet not statically type safe, and one effectively type safe. Creating a full statically type safe solution is left as an exercise to the reader, providing the reader is looking for a subject for a PhD thesis.

I have used this this pattern in production code for analyzing emails, drawing tables, building UI, and handling JMS messages; I hope you'll find it useful too.

As you can see, not only is The Match Maker Design Pattern - a New Place for the Actions interesting and informative, it's also fun to read!

In Java Today, Frank Kieviet, departing manager of the OpenESB project, presents Working with tips and tricks for project owners:

In the past two years I've managed the OpenESB open source project. This project is hosted on In this post I outline a number of tips and tricks I've learned while managing this project on This is useful information for my successor, but it also may be useful to other people who are managing projects on Web presence: An important factor in the success of an open source project is its web presence: it will be the first point of contact between a potential new user and the project. New visitors will want to see answers to these four items immediately...

Pelegri presents Fundamo, OSGi, iPad.. and More GlassFish News - April 24rd, 2010:

Financial services on the go - GlassFish for Fundamo and profit: Alexis recently published a new Adoption Story on how Fundamo uses GlassFish v2 and OpenMQ for its Enterprise Platform. Overview at stories entry, details in questionnaire, and an overview in this earlier short video interview. We are always interested in more GlassFish adoption stories, both from (non-paying) users and from (paying) customers.   Stories come from all industries and around the world, the last few entries are PSA Peugeot Citroën (France/Auto), iVox (Belgium/Print), NHIH (US/Gov-Health Care) and Suncorp (Australia/Finantial)...

James Sugrue continues his design pattern series with Design Patterns Uncovered: The Mediator Pattern:

Today's pattern is the Mediator pattern, used to handle complex communications between related objects, helping with decoupling of those objects. Mediator in the Real World: An airport control tower is an excellent example of the mediator pattern. The tower looks after who can take off and land - all communications are done from the airplane to control tower, rather than having plane-to-plane communication. This idea of a central controller is one of the key aspects to the mediator pattern...

Geerjan Wielenga continues his Small MultiView Editor Experiment (Part 2):

The sample for developers creating multiview editors on the NetBeans Platform (described yesterday in this blog) is now slightly more extensive, since you can add new nodes in the visual view, which will then automatically be added to the source editor (as well as the visual editor, of course)...

In the Weblogs, Kohsuke Kawaguchi is Introducing InfraDNA, the Hudson company:

As I wrote in my farewell note, I was working on starting a new company around Hudson. It took longer than I initially anticipated, but it's finally open for business! The company will provide two things; one is support, so that I can answer your questions and problem reports in a timely fashion, and the other is consulting, so that I can help you develop custom plugins, or provide on-site support to work on some tricky problems. The name of the company is InfraDNA because I think of Hudson more as an infrastructure on which all kinds of server-side automation/tools can be built/deployed, and because I think this stuff is built into me (as in DNA)...

John Ferguson Smart describes Grouping tests using JUnit categories:

In a well-organized build process, you want lightning-fast unit tests to run first, and provide whatever feedback they can very quickly. A nice way to do this is to be able to class your tests into different categories. For example, this can make it easier to distinguish between faster running unit tests, and slower tests such as integration, performance, load or acceptance tests. This feature exists in TestNG, but, until recently, not in JUnit. Indeed, this has been missing from the JUnit world for a long time...

In the Forums, kschaefe expresses his view in the SwingLabs forum on JXEditorPane honoring display properties: I believe that we should change the default construction of JXEditorPane to honor display properties. This means that when the font or colors are set the rendered documents will honor them. Core added this client property in 1.5, but left the old style...

In the Metro and JAXB forum, John Hite asks Where is databinding done?: I'm trying to figure out where metro converts SOAP messages to java objects. Is this done in a Tube? Can anyone point me in the right direction? Thanks, John

In the LWUIT forum, rgucci finds that Calling BlackBerry browser to play video blocks the whole device: Developing on the BlackBerry port, OSv5.0, Bold 9700 simulator. I am calling the native BlackBerry Browser to launch the BlackBerry media player to play an mp4 file stored in the SDCard. Everything works and plays, the video and sounds are...

Our Spotlight this week is the NetBeans IDE 6.9 Beta Release:

NetBeans 6.9 Beta introduces the JavaFX Composer, a visual layout
tool for visually building JavaFX GUI applications, similar to the Swing
GUI builder for Java SE applications. Additional highlights include OSGi
interoperability for NetBeans Platform applications; support for JavaFX
SDK 1.3, PHP Zend framework, and Ruby on Rails 3.0; as well as
improvements to the Java Editor, Java Debugger, and issue tracking, and
more. NetBeans 6.9 Beta is available in English, Brazilian Portuguese,
Japanese and Simplified Chinese, as well as in several
community-translated languages. Learn more:

This week's Poll asks What is the most important enhancement in JavaFX 1.3? The poll will be open through Friday.

Our latest Feature Article is The Match Maker Design Pattern - a New Place for the Actions, by Michael Bar-Sinai, which describes how to add actions to a system without modifying business objects, add objects without changing actions, and still keep things reusable. We also just published HTML5 Server-Push Technologies, Part 2 by Gregor Roth; this two-part series explains the new Server-Sent Events and WebSockets API in HTML5. And we're also still featuring Biswajit Sarkar's Using Styles, Themes, and Painters with LWUIT, in which you discover how to use some of the new and enhanced features in LWUIT version 1.3.

Current and upcoming Java Events:

Registered users can submit event listings for the Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.

Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of it will be archived along with other past issues in the Archive.

-- Kevin Farnham

O'Reilly Media
Twitter: @kevin_farnham