Whether you are a software manager, designer, engineer, or student, design patterns are the best foundation on which to design and build software projects. One of the first examples of applying design patterns to software was in the classic book Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley, 1995), written by the Gang of Four (GoF) ”Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. This chapter helps you bridge the gap between the highly abstract GoF presentation and the real-world challenges of writing code. If design patterns are used as Sun suggests, and this chapter echoes, they become a core asset of any software shop. Patterns show developers how to systematically solve problems created by market and technology forces. So where do design patterns fit in the design hierarchy? You often hear about two-tier, three-tier, and multitier applications. The number of tiers refers to the number of major responsibilities. For example, a three- tier application has presentation, logic, and database tiers. Another way of thinking about an application is in layers of abstractions, from most granular to most general, as described in the following list:
You need to traverse all these layers to produce a successful solution. Although the Token and Statement layers are simple, the remaining layers require increasingly sophisticated ideas. In fact, I propose that starting at the Algorithm layer, the evaluator should begin deducting points if the algorithm isn't designed right. The seat search (your instructions might call it something like "criteria search") is actually listed in the scoring section of the instructions. The instructions also name specific design patterns. You will definitely use the Model-View-Controller (MVC) pattern in the GUI (Swing technology is built with it), and most candidates use Value Object for transporting database query results back to the requesting GUI (the approach my solution used through RMI). Your evaluator hopes to find good use of preexisting J2SE classes throughout your code. For example, my lock manager used the Collection framework in the form of a HashMap . Evaluators would rather see smart reuse than invention. Last, your architecture has to be effective. A GUI ”socket ”RMI ”database architecture, for example, would be weak because the socket portion, which is already implemented in RMI, is unnecessary. This chapter defines and describes the patterns you will most likely use in your solution and throughout your career as you address enterprise design needs. The term "pattern" comes from the architect Christopher Alexander, who wrote several books on the topic of patterns. Alexander, a building architect, was the first to "codify" patterns for architecture. Although he was interested in urban planning and building architecture, his notions were clearly useful in many areas and isolated the concept of patterns better than anyone before him. Alexander is one of those rare people who take a step back and question why people do things the way they do. He gave the result of his inquiry the name "pattern language" and defined it at length in his seminal book, A Pattern Language: Towns, Buildings , Construction (by Christopher Alexander, Sara Ishikawa, and Murray Silverstein; Oxford University Press, 1977). While Alexander was thinking buildings and foundations, it became clear to many that his design patterns were abstract enough to be useful elsewhere. That is when the GoF applied patterns to software in Design Patterns: Elements of Reusable Object-Oriented Software . It took a while, but the GoF started a groundswell. There are now dozens of books, and many more on the way, about design patterns. Design patterns are often defined as "a solution to a problem in a context." This falls short of the abstract definition that experts prefer, however. Suppose you have an object that makes copies of files. What is the design pattern? You don't know yet, so throw in an object that copies the content of one text box to another. Something about the copying process is the same between the two objects. Neither the files nor the text boxes differ , but the copying is the same. Therefore, the sameness is copying. By itself, this isn't a pattern, but you're on the way to finding one. What are design patterns? Sun defines them in the following way: "A design pattern describes a proven solution to a recurring design problem, placing particular emphasis on the context and forces surrounding the problem, and the consequences and impact of the solution." Design Pattern ElementsThere are many ways to define a pattern, but the classic way is to describe its elements or aspects. There are several lists of elements in the current literature. I've used a dolled-up version of the GoF's approach, which centers on three basic elements ” context, problem , and solution :
The design pattern is not only these three elements, but the relationship between them and the formal language that describes the whole business. That is a lot of heady language and is certainly not on the exam directly, but understanding these relationships will help you select and correctly apply design patterns to your solution. Remember that context, problem, and solution are at the core of design patterns. The following list of pattern elements is my way of expanding on the three basic elements to give you a way to understand the essence of a given pattern:
|