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

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.