Enterprise Patterns

Dr. Dobb's Journal February, 2005

By Martin Heller

Martin is a web and Windows programming consultant and Senior Contributing Editor at BYTE.com. He can be contacted at http://www.mheller.com/.

Patterns of Enterprise Application Architecture
Martin Fowler
Addison-Wesley, 2003
533 pp., $49.99
ISBN 0321127420

Transmitting wisdom and experience can be difficult in any sphere of activity. Probably the closest that software architects have come to a reliable way of transmitting their wisdom and experience is by abstracting patterns from their applications.

Patterns are a form of "chunking," which provides both a higher level way of thinking about a subject, and a common vocabulary. If I recognize the opening moves in a chess game as the Queen's Gambit, I know the choices before me and their most likely consequences. If I tell another chess player I played Queen's Gambit Declined, my meaning is clear without having to detail the moves made. Similarly, if I recognize that I have an application that needs to load and display what could turn out to be a very large database, I know I can avoid bringing the entire database into memory with a Lazy Load pattern, and I can mention the pattern to another software developer without having to draw diagrams to explain what I mean.

Patterns don't generally represent new inventions: What they reflect are old inventions that could be used for other things. Wheels, threads, and gears are all common patterns for mechanical engineers. Patterns are for things that are done over and over, so that you don't have to reinvent them each time you need them, even if the application varies each time.

There have been a number of books on software patterns over the last 9 or 10 years. Probably the best known is the seminal Design Patterns by Gamma, Helm, Johnson, and Vlissides (Addison-Wesley, 1995), also known as the "Gang of Four" or "GoF." The Gang of Four patterns are fairly low level but universal: creational patterns, such as Factory Method and Singleton; structural patterns, such as Composite and Proxy; and behavioral patterns, such as Iterator and State. Since the publication of Design Patterns, higher level and more applied patterns, such as the aforementioned Lazy Load, have become fodder for books.

Martin Fowler is well known as an OOD/OOP guru (or "object bigot," as he calls himself), and is the author of Analysis Patterns, UML Distilled, Planning Extreme Programming, and Refactoring. In his fifth book, Patterns of Enterprise Application Architecture, Fowler discusses 40 design patterns that are appropriate for enterprise applications. As Fowler explains in the preface:

Enterprise applications are about the display, manipulation, and storage of large amounts of often complex data and the support or automation of business processes with that data. Examples include reservation systems, financial systems, supply chain systems, and many others that run modern business. Enterprise applications have their own particular challenges and solutions, and they are different from embedded systems, control systems, telecoms, or desktop productivity software.

The book has two major sections: the narratives and the patterns. Fowler expects you to read through all the narratives and then use the patterns for reference as the need arises.

The narratives introduce some common problems encountered in enterprise applications and discuss their solutions at a high level, so that you can get a feel for which patterns solve what problems, and for how the patterns interrelate. The chapters in Part 2 are detailed references to the patterns themselves, covering how they work, when to use them, and sample applications and implementations. The sample code is written in Java or C#, and illustrated with UML diagrams. The front inside cover of the book lists the patterns alphabetically; the back inside cover is a "cheat sheet" for finding the correct pattern to solve a problem.

Patterns of Enterprise Application Architecture covers domain logic patterns, like Domain Model and Table Module; data source architectural patterns, like Table Data Gateway and Data Mapper; object-relational behavioral patterns, such as Unit of Work and Lazy Load; object-relational structural patterns, such as Foreign Key Mapping and Concrete Table Inheritance; object-relational metadata mapping patterns, such as Query Object and Repository; web presentation patterns, such as Model View Controller and Front Controller; distribution patterns; offline concurrency patterns; session state patterns; and base patterns, such as Gateway, Layer Supertype, and Registry. The book does not cover asynchronous messaging, rich-client interfaces, validation, error handling, security, or refactoring.

Although he wrote the bulk of the exposition and sample code himself, Fowler had five contributors: David Rice, Matthew Foemmel, Edward Hieatt, Robert Mee, and Randy Stafford. Rice assisted with the excellent chapter on concurrency, and provided several patterns; Foemmel assisted with several examples and patterns; Hieatt and Mee provided the Repository pattern; Stafford provided the Service Layer pattern.

Overall, Patterns of Enterprise Application Architecture is an excellent treatment of its subject matter. If you are an architect or developer working on Enterprise or Enterprise-style applications—that is, applications that work with large amounts of data—you'll find the time spent learning these patterns more than worthwhile, whether they are new to you or familiar.

DDJ