TweetFollow Us on Twitter

Patterns Volume Number: 17 (2001)
Issue Number: 1
Column Tag: Software Engineering

Patterns

By By Paul E. Sevinç, Switzerland

Introduction

Reuse is a key objective of software engineering. A well-known form of reuse is code (i.e., implementation) reuse, as promoted by a procedure library for instance. A domain-specific framework also promotes implementation reuse, and in addition the reuse of analysis (namely of the domain) and design (that led to the architecture of the framework). Capturing and passing on analysis and design experience without the need for code can be achieved by the use of patterns.

In this article, we give definitions of pattern, analysis pattern, design pattern, and architectural pattern. (In a future article on frameworks, we will also discuss the relationship between patterns and frameworks.) We do not, however, recap the history of patterns (see, for instance, Appleton [3]). Nevertheless, note that software-development patterns were inspired by Christopher Alexander who, in the 1970s, developed a pattern language for architecture [2]-the "house-building" discipline, that is, not software or computer architecture!

Pattern

Patterns are schematic, proven solutions to recurring problems. Basically, patterns are characterized by at least a name, a problem description, and a problem solution [15]. A well-known name allows us to concisely refer to a specific pattern. It is certainly easier to refer to "the Adapter pattern" (see the example below) than "the pattern that consists of entities which...". The problem description tells us in what situations the respective pattern is applicable. It includes conditions that must be met before applying the pattern. The problem solution explains how we can solve the problem. It typically does so as abstractly as makes sense for the particular kind of pattern.

"Schematic" refers to the fact that, especially in patterns books, patterns are usually discussed according to some template. (For the sake of brevity, we will not do that in this article.) Different authors use different templates [e.g., 6, 11]. "Recurring" refers to the fact that a problem/solution pair must be observed at least three times to be accepted as a pattern.

Let us look at a simple example, the Adapter pattern. Assume that, in a certain context, we defined the interface of encryption/decryption Java classes to be as shown in Listing 1.

Listing 1

public interface Cipher
{
   void encrypt( int[] plainText, int[] cipherText );
   void decrypt( int[] cipherText, int[] plainText );
}

Now we would like to have a Cipher instance that performs IDEA-encryption and -decryption [14]. For that, we need a concrete class that implements the Cipher interface. We could, of course, develop such a class from scratch. However, a good soul already did most of the hard work by developing a class that realizes IDEA and even made its source code freely available (see Listing 2). We are going to reuse this class.

Listing 2

public class IDEA
{
   // fields
   ...
   
   public IDEA( int[] secretKey )
   {
      ...
   }
   
   public void cipher( boolean flag, int[] source, int[] drain )
   {
      ...
   }
   
   // private methods
   ...
}

One problem remains, though: the type IDEA is not a subtype of Cipher, but Java is strongly typed. And even if Java was not strongly typed, we would still have a problem since the interfaces did not match in the first place.-Enter the Adapter pattern. Instead of forgetting about the IDEA class altogether or of copying and modifying its source code (a highly error-prone approach), the Adapter pattern suggests to develop a class, a subtype of Cipher, that simply forwards requests to IDEA (see Listing 3).

Listing 3

public final class IDEACipher implements Cipher
{
   private final static int keyLength = 16;
   
   private final IDEA adaptee;
   
   public IDEACipher( int[] key ) throws InvalidKeyException
   {
      if ( key.length != keyLength ) {
         throw new InvalidKeyException( "..." );
      }
      
      for ( int i = 0; i < keyLength; ++i ) {
         if ( key[ i ] < 0 || key[ i ] > 255 ) {
            throw new InvalidKeyException( "..." );
         }
      }
      
      adaptee = new IDEA( key );
   }
   
   public void encrypt( int[] plainText, int[] cipherText )
   {
      adaptee.cipher( true, plainText, cipherText );
   }
   
   public void decrypt( int[] cipherText, int[] plainText )
   {
      adaptee.cipher( false, cipherText, plainText );
   }
}

Note that, since IDEA was developed first, we could also have defined IDEACipher as shown in Listing 4.

Listing 4

public final class IDEACipher extends IDEA implements Cipher
{
   // see Listing 3
   ...
   
   public void encrypt( int[] plainText, int[] cipherText )
   {
      super.cipher( true, plainText, cipherText );
   }
   
   public void decrypt( int[] cipherText, int[] plainText )
   {
      super.cipher( false, cipherText, plainText );
   }
}


Figure 1. Object Adapter (adapted from [11])

The Adapter variant of Listing 3 is called the Object Adapter (it connects objects at run time through a reference, see Figure 1). The Adapter variant of Listing 4 is called the Class Adapter (it connects classes at compile time through inheritance, see Figure 2). In Java, we clearly prefer the Object Adapter over the Class Adapter. But in C++, where IDEACipher could have inherited privately from IDEA (and thus not be of type IDEA), the Class Adapter is a viable alternative.


Figure 2. Class Adapter (adapted from [11])

In short: Name: Adapter (also know as Wrapper)

Problem Description: Class (Adaptee) whose implementation cannot be reused (by Client) because its type or at least its interface does not meet certain requirements.

Problem Solution: Develop a class (Adapter) whose type or interface does meet above-mentioned requirements and whose implementation mainly consists of forwarding requests to (and returning replies from) Adaptee in a suitable form.

Architecture and Design

According to Stroustrup [23], software development is an iterative and incremental process basically consisting of analysis, design, and implementation, where the software design steps result in the software architecture. This view of architecture being the result of design is not uncommon. And we adopted it in the first paragraph of the introduction, when we said that framework design leads to the framework architecture.

However, the software-engineering community in general and the patterns community in particular denote by architecture another software-development step (analysis, architecture, design, implementation). We adopted the latter view in the last paragraph of the introduction, when we considered architecture to be a discipline, and for the remainder of this article.

So what is architecture? Just as is the case for components [22, CS99], the software-engineering community is struggling with a definition for architecture [4, 7]. Very, very loosely speaking, architecture is coarse-grained design (higher level), and design is fine-grained architecture (lower level).

Analysis Pattern, Architectural Pattern, and Design Pattern

Many kinds of patterns exist. And more often than not, there are different definitions for the "same" kind of pattern. A prime example is the term "design pattern" which sometimes denotes patterns in general and sometimes a particular class of patterns (as it does in this article).

As a basis for further discussion, we quote five definitions from the literature:

Analysis Pattern

Richter [16, p. 344]:
"An analysis pattern is a way of solving a problem in a particular problem domain."

Architectural Pattern

Richter [16, p. 345]:
"An architectural pattern is a problem-independent way of organizing a system or subsystem. It describes a structure by which the different parts of a system are organized or interact."

Buschmann et al. [6, p. 12]:
"An architectural pattern expresses a fundamental structural organization schema for software systems. It provides a set of predefined subsystems, specifies their responsibilities, and includes rules and guidelines for organizing the relationships between them."

Design Pattern

Richter [16, p. 345]:
"A design pattern is a solution to a small problem that is independent of any problem domain. It represents an attractive solution to a design problem that could occur in any kind of application. The same design pattern can be applied in areas as diverse as order processing, factory control, and meeting room scheduling."

Buschmann et al. [6, p. 13]:
"A design pattern provides a scheme for refining the subsystem or components of a software system, or the relationships between them. It describes a commonly-recurring structure of communicating components that solves a general design problem within a particular context [11]." (Note: here, "component" means software entities in general, not components in the more narrow sense of component-oriented programming [22, CS99].)

Examples

Example analysis patterns can be found in Fowler's book [8] and on his homepage [9].

Probably one of the most successful architectural patterns is the Layers [6, p. 31]:

"The Layers architectural pattern helps to structure applications that can be decomposed into groups of subtasks in which each group of subtasks is at a particular level of abstraction."


Figure 3. Layers [6]

Well-known examples of the Layers pattern are the ISO Open System Interconnection (OSI) model (layers: application, presentation, session, transport, network, data link, and physical) or the Java platform (host operating system, Java run-time environment, Java application). Buschmann et al. [6] and Szyperski [24] discuss several variants of Layers.

We do not need to discuss this pattern any further as you are most certainly very familiar with this fundamental architecture. And even if you are not impressed by the Layers at all, it is an excellent example: Patterns are about sound solutions to realistic problems, not about the most elaborate solution to an exotic problem.

The Adapter pattern is one example of a design pattern. Another one is the Wrapper Facade [20]:

"The Wrapper Facade design pattern encapsulates the functions and data provided by existing non-object-oriented APIs within more concise, robust, portable, maintainable, and cohesive object-oriented class interfaces."


Figure 4. Wrapper Facade [20]

As shown in Figure 4, the intent of the Wrapper Facade is to keep an object-oriented application purely object-oriented even though it relies on a procedure-oriented library. Again, the pattern is about an easy-to-understand solution to an easy-to-understand problem.-Nevertheless, the study of patterns is worthwhile: quite a few patterns discuss not-so-obvious (albeit highly elegant) solutions to non-trivial problems.

Discussion

First, note how Richter emphasizes the domain-specific nature of analysis patterns and the domain-independent nature of architectural and design patterns. (Riehle and Züllighoven [18] make a similar distinction between conceptual patterns and design patterns.) Do not take these definitions too literally, though. As Fowler remarks [10], an analysis pattern from one domain can prove useful in a completely different domain. And sooner or later, you will stumble over deceptively contradictory patterns categories such as "security architectural patterns" or "GUI design patterns". This can either mean that a set of general-purpose patterns has been collected for a particular domain, or that a pattern is domain-specific (e.g., for GUIs) but still general enough to be applicable in different situations within that domain (e.g., for different widgets).

Next, both architectural patterns and design patterns are language independent. (Language dependent patterns are called idioms [6] or programming patterns [18], by the way.) And architectural patterns are also paradigm independent. The layers in Figure 3 could each consist of a set of procedures, or some could consist of classes and some of functions, etc. Design patterns on the other hand are typically object oriented. The Wrapper Facade is a border case.

Finally, rotate Figure 4 by 90 degrees and you will see-the Layers (layers: Application, WrapperFacade, Functions)! It should come to no surprise that design patterns refine architectural patterns. However, sometimes it is difficult to determine which design pattern to apply for the refinement. As we said in the introduction, patterns help capturing and passing on experience, but they do not make experience obsolete.

To Probe Further

A good starting point for pattern-related information on the Web is the patterns home page of the Hillside group [12]. And many authors of the patterns community provide information on their personal home pages (e.g., Riehle [17] or Schmidt [19]).

A must-read is Gamma et al.'s Design Patterns [11]. The publication of this seminal book triggered the intensive search for patterns that continues unabated today. Code examples are given in C++ and Smalltalk, so you may want to take a look at Lalonde's article [13]. We hope that the authors will take the time to publish a second edition. This would allow them to modify the diagrams to be UML compliant and to extend the "Known Uses" sections with examples from the Java platform.

A should-read is Buschmann et al.'s Pattern-Oriented Software Architecture [6] which pioneered architectural patterns. In newer publications, this book is also referred to as POSA 1, because other books with the same main title have been published or are in preparation.

The patterns community has its own conference and publishes the proceedings in the Pattern Language of Program Design series [1].

One book you may want to take a look at as well is Brown et al.'s AntiPatterns [5], some sections of which are pretty good while others cannot keep up with the rest of the book. Whether antipatterns really are a concept of their own or just patterns whose template also includes a bad problem "solution" encountered in practice is debatable.

Alas, now that patterns entered the mainstream, a few books are on the market that only try to cash in on a buzzworld-enabled title.

Acknowledgments

This article is partly based on a chapter in my M.S. thesis [21] that was proof-read and commented on by Prof. Dr. Rachid Guerraoui, Dr. Jean-Philippe Martin-Flatin, Luc Girardin, and Dani Seelhofer.

I would like to thank Dr. Dirk Riehle for proof-reading and commenting on the current version.

References

  • [1] Addison-Wesley. Software Patterns Series. Home Page.
    Located at <http://cseng.aw.com/catalog.taf?ctype=series&seriesid=34>.
  • [2] C. Alexander. "The Origins of Pattern Theory: The Future of the Theory, and the Generation of a Living World". IEEE Software, Vol. 16, No. 5, pp. 71-82, September/October 1999.
  • [3] B. Appleton. "Patterns and Software: Essential Concepts and Terminology". Available at <http://www.enteract.com/~bradapp/docs/>.
  • [4] Bredemeyer Consulting. Resources for Software Architects. Home Page. Located at <http://www.bredemeyer.com/>.
  • [5] W.H. Brown, R.C. Malveau, H.W. McCormick III, and T.J. Mowbray. AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis. John Wiley & Sons, New York 1998.
  • [6] F. Buschmann, R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Chicester, 1996.
  • [7] Carnegie Mellon Software Engineering Institute. Architecture Tradeoff Analysis Initiative. Home Page.
    Located at <http://www.sei.cmu.edu/ata/ata_init.html>.
  • [8] M. Fowler. Analysis Patterns: Reusable Object Models. Addison-Wesley, Reading (Massachusetts), 1997.
  • [9] M. Fowler. Analysis Patterns. Home Page.
    Located at <http://www.martinfowler.com/apsupp/index.html>.
  • [10] M. Fowler with K. Scott. UML Distilled: A Brief Guide to the Standard Object Modeling Language. Addison-Wesely, Reading (Massachusetts), 2nd edition 2000.
  • [11] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesely, Reading (Massachusetts), 1995.
  • [12] Hillside Group. Patterns Home Page. Home Page.
    Located at <http://hillside.net/patterns/>.
  • [13] W. Lalonde. "I can read C++ and Java, But I Can't Read Smalltalk". JOOP, Vol. 12, No. 9, pp. 40-45, February 2000.
  • [14] A. Menezes, P. van Oorschot, and S. Vanstone. Handbook of Applied Cryptography. CRC Press, New York, 1997.
  • [15] H. Mössenböck. Objektorientierte Programmierung in Oberon-2. Springer, Heidelberg, 3rd edition 1998.
  • [16] C. Richter. Designing Flexible Object-Oriented Systems with UML. Macmillan Technical Publishing, Indianapolis, 1999.
  • [17] D. Riehle. Dirk's Home Page. Home Page.
    Located at <http://www.riehle.org/>.
  • [18] D. Riehle and H. Züllighoven. ìUnderstanding and Using Patterns in Software Development". Theory and Practice of Object Systems, Vol. 2, Nr. 1, pp. 3-13, 1996.
  • [19] D.C. Schmidt. Douglas C. Schmidt's Welcome Page. Home Page.
    Located at <http://www.cs.wustl.edu/~schmidt/>.
  • [20] D.C. Schmidt, M. Stal, H. Rohnert, and F. Buschmann. Pattern-Oriented Software Architecture: Patterns for Concurrent and Networked Objects. John Wiley & Sons, Chicester, 2000.
  • [21 P.E. Sevinç. Design Patterns for the Management of IP Networks. M.S. Thesis, Swiss Federal Institute of Technology Zurich, February 2000.
  • [22] Software Development Magazine. Beyond Objects. Column by B. Meyer, B. Powel Douglas, and C. Szyperski.
    Available at <http://www.sdmagazine.com/uml/beyondobjects/>.
  • [23] B. Stroustrup. The C++ Programming Language. Addison-Wesley, Reading (Massachusetts), 3rd edition 1997.
  • [24] C. Szyperski. Component Software: Beyond Object-Oriented Programming. Addison-Wesely, Reading (Massachusetts), 1998.

Paul E. Sevinç currently works as a software engineer for Switzerland-based Teamup AG. From January 2001 on, he will work for Trilogy Software, Inc. in Austin (Texas) and Paris (France). You can reach him at paul.sevinc@ubilab.org.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.