Skip to main content

Breaking up not so hard to do

Posted by daniel on August 17, 2004 at 8:37 AM PDT

Separating from a class you don't control

If I were a design pattern, I think I would be the Adapter. Sure, I thought I could be a Command pattern, but I don't like people telling me when to do things.

In Robert C. Martin's latest article The Adapter Pattern he starts with the following:

public class Button {
  private Light light;

  public Button(Light light) {
    this.light = light;
  }

  public void press() {
    light.turnOn();
  }
}

Uncle Bob asks, if you can not modify Light, then how do you decouple the Button from the Light. In the code snippet the Button knows about the turnOn() method in the Light. He refers to his first solution as the object version of the Adapter. He introduces an interface named Switchable that the Button knows about. He then introduces a LightAdapter class that implements Switchable and contains a handle to a Light object. The second pass is the class form of adapter. As before the Button depends on an object of type Switchable (an interface). This time, however, the LightClassAdapter implements Switchable and extends Light. After railing against the limitations of single inheritance, Bob shows how to implement object-form Adapters as anonymous inner classes.

So once I realized it was too much work to be an Adapter myself, I was thinking I could be a Chain of Responsibility pattern, but In Projects and Communities, the JavaWorld article on the Chain of Responsibility discusses pitfalls and how to improve on the classic implementation.

The Jini community announces the update to Jan Newmarch's Guide to Jini Technologies that now covers the Jini 2.0 release.


In
Also in Java Today
, Srini Penchicala has written a guide to Monitoring and Managing Tomcat Clusters Using JMX. His introduction says "the Tomcat 5 servlet container provides built-in support for monitoring server components using the Java Management Extensions (JMX) API. This article concentrates on the clustering and load balancing components, and provides an overview of configuring and using JMX MBeans in managing the elements in a J2EE cluster. You'll also see how to use the JMX API to automate various administration tasks in the Tomcat container."

Some point, usually early in your Java career, you have wrestled with classpath. The article IBM Cloudscape: Understanding Java class path takes Java newbies who are cloudscape users through the fun of setting up this environment variable. Cloudscape is a small Java database.


Alex Toussaint reports JSR 94: Java Rule Engine API - Final in today's Weblogs.This was his first JSR and he reports that "On the one hand, you have great discussions around the technology itself and trying to figure out some of the best ways of doing certain things. You also get to work with very smart people who have different perspectives which helps open your horizons. All of this is cool. On the other hand though... you have to deal with the legal stuff like distribution licenses, export controls, and achieve compromises in order to move things forward to a final state."


You don't want to hassle with doing something about an exception so you put in an empty catch block and figure it's been taken care of. In today's Forums. moderator Ron Hitchesns writes "Empty catch blocks are ticking time bombs. Do you ever silently swallow exceptions? How many times have you run across this in other peoples code? Are catch blocks that just print a stack trace and keep going any better? Do IDE tools that auto-generate empty try/catch blocks exacerbate this problem?"

Johnm writes on referring to objects by their interfaces saying
"Refactoring is a marvelous tool that we in the software business have but even refactoring is not a silver bullet. There are some categories of risk for which the pro-active mitigation costs are much smaller than the costs of dealing with the potential negative outcomes."


In today's java.net News Headlines
:

Registered users can submit news items for the href="http://today.java.net/today/news/">java.net News Page using
our news submission
form
. All submissions go through an editorial review before being posted to the site. You can also subscribe to
thejava.net
News RSS feed
.


Current and upcoming
Java Events
:

Registered users can submit event listings for the href="http://www.java.net/events">java.net Events Page using our href="http://today.java.net/cs/user/create/e"> 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
java.net
it will be archived along with other past issues in the href="http://today.java.net/today/archive/">java.net Archive.