You are currently browsing the daily archive for October 18, 2006.

Most Important Patterns (Top 6)

Shortly a developer asked me, what are the most know-worthy patterns. My answer was:

  1. Facade: it decouples independent classes, and more important, increases the granularity. Session Facade from Java EE is a sample.
  2. Adapter: makes incompatible things compatible. Especially important in server programming, in case you have to talk to legacy backend systems like SAP, CICS or IMS. Business Delegate in J2EE 1.4 (catches RemoteExceptions and throws something else), DAOs or JCA Connectors are adapters.
  3. Decorator: Enhances an interface (in our case the Facade), with additional aspects (it is actually the beginning of AOP :-)). In Java EE we have the Servlet Filter, Interceptors or implicit decoration with transactions, state or security. In Java SE the whole package is a decorator.
  4. Interface (actually not a standard pattern): is needed for encapsulation, decoupling the clients from the interface realization, and so is the beginning of service orientation or SOA.
  5. Factory/Builder: encapsulates the creation of differnt implementations for a Java-Interface. Can be a part of a framework (see Spring or Java EE 5), or of project architecture.
  6. Command: provides a simple and stable interface (often one method with name like execute, go, run, actionPerformed etc). The implementation provides the behavior, having the only the interface, it is not possible to see what happens :-). Command is the foundation of JMS, the whole SOA (stands for Same Old Architecture :-)) and also the event handling of frameworks like swing (ActionListener), or Struts (Actions).

So a typical J2EE 1.4/Java 5 architecture consist of:
Business Delegate (Adapter + Factory) ——> Decorator (Transactions, Logging, Security) + Session Facade¬† (Facade), a bunch of POJOs or Session Beans, and some DAOs (Adapter) or connectors to the backends. Message Driven Beans (Command) are often used for batch processing.

It’s amazing, but it is possible to build almost every architecture with these building blocks.

Ref:¬† Adam Bien’s Weblog