4.2 Defining Lightweight

Overview

Much conversation has been had online about heavyweight Java versus lightweight Java. Here we attempt to add our perspective.

Martin Fowler said much with this article : http://www.martinfowler.com/articles/injection.html (Inversion of Control Containers and the Dependency Injection pattern)

Marker interfaces

public class Foo implements OurComponent {
  // fields, ctors, methods, etc ...
}
public interface OurComponent {
}

 

We don't particularly like interfaces that are there simply to mark a class as part of particular component framework. Its not very transparent. It also is not something you can easily add to another team's codebase if you want to use their component as one of your components.

extends, implements, throws, @attributes and prefixedOrPostfixedMethods()

public class Foo extends BaseComponent {
  // fields, ctors, methods, etc ...
}

 

Extending a base class is pretty obviously a heavy thing to do. So is the mandatory implementing an interface for a forced design. This is mentioned above for marker interfaces, but also true for interfaces with methods that have to be mandatarily implemented.

Similarly, and a lot less common is suggesting that component's methods need to throw something or have some other clue that helps the framework:

public class Foo {

  // fields, ctors,

  public void foo() throws FrameworkException {
    // ...
  }

  public void xyzFrameworkInitBar(Bar bar) {
    // ...
  }

  @XyzFramework
  public Blortable blort() {
    // ...
  }

}

 

EJB 2.0 versus EJB 3.0

EJB had a very heavyweight model. The beans, as such, did not even directly implement their interfaces..

public interface Foo extends EJBObject {
    void foo() throws RemoteException;
}

public class MyBean implements SessionBean {

    protected SessionContext sessionContext = null;

    public void ejbCreate(String oneOr, String moreArgs) {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void ejbRemove() {
    }

    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
    }

    public void foo() {
      // ..
    }

 

Wheras EJB 3.0 is a little more lightweight ..

@remote
public class MyBean {
    public void foo() {
      // ..
    }

 

From the client usage point of view

TODO

From the implementors point of view.

TODO

Labels

 
(None)