Design Patterns Uncovered: The Interpreter Pattern

Today’s pattern is the Interpreter pattern, which defines a grammatical representation for a language and provides an interpreter to deal with this grammar.

Interpreter in the Real World

The first example of interpreter that comes to mind, is a translator, allowing people to understand a foreign language. Perhaps musicians are a better example: musical notation is our grammar here, with musicians acting as interpreters, playing the music.

Design Patterns Refcard
For a great overview of the most popular design patterns, DZone’s Design Patterns Refcard is the best place to start.

The Interpreter Pattern

The Interpreter pattern is known as a behavioural pattern, as it’s used to manage algorithms, relationships and responsibilities between objects.. The definition of Interpreter as provided in the original Gang of Four book on Design Patterns states:

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

The following diagram shows how the interpreter pattern is modelled.

Context contains information that is global to the interpreter. The AbstractExpression provides an interface for executing an operation. TerminalExpression implements the interpret interface associated with any terminal expressions in the defined grammar.

The Client either builds the Abstract Syntax Tree, or the AST is passed through to the client. An AST is composed of both TerminalExpressions and NonTerminalExpressions. The client will kick off the interpret operation. Note that the syntax tree is usually implemented using the Composite pattern

The pattern allows you to decouple the underlying expressions from the grammar.

When Would I Use This Pattern?

The Interpreter pattern should be used when you have a simple grammar that can be represented as an Abstract Syntax Tree. This is the more obvious use of the pattern. A more interesting and useful application of Interpreter is when you need a program to produce different types of output, such as a report generator.

So How Does It Work In Java?

I’ll use a simple example to illustrate this pattern. We’re going to create our own DSL for searching Amazon. To do this, we’ll need to have a context that uses an Amazon web service to run our queries.

//Context
public class InterpreterContext
{
	//assume web service is setup
	private AmazonWebService webService;

	public InterpreterContext(String endpoint)
	{
		//create the web service.
	}

	public ArrayList<Movie> getAllMovies()
	{
	   return webService.getAllMovies();
	}

	public ArrayList<Book> getAllBooks()
	{
	  return webService.getAllBooks();

	}
}

Next, we’ll need to create an abstract expression:

//Abstract Expression
public abstract class AbstractExpression
{
   public abstract String interpret( InterpreterContext context);
}

We’ll have many different expressions to interpret our queries. For illustration,let’s create just one:

//Concrete Expression
public class BookAuthorExpression extends AbstractExpression
{

	private String searchString;

   public BookAuthorExpression(String searchString)
   {
		this.searchString = searchString;
   }

   public String interpret(InterpreterContext context)
   {
		ArrayList<Book> books = context.getAllBooks();
		StringBuffer result = new StringBuffer();
		for(Book book: books)
		{
			 if(book.getAuthor().equalsIgnoreCase(searchString))
			 {
				result.append(book.toString());
			 }
		}
		return result;

   }

}

Finally, we need a client to drive all of this. Let’s assume that our language is of the following type of syntax:

books by author 'author name'

The client will determine which expression to use to get our results:

//client
public class AmazonClient
{

 private InterpreterContext context;

 public AmazonClient(InterpreterContext context)
 {
	this.context = context;
 }

 /**
  * Interprets a string input of the form
  *   movies | books by title | year | name '<string>'
  */
 public String interpret(String expression)
 {
	//we need to parse the string to determine which expression to use 

	AbstractExpression exp = null; 

	String[] stringParts = expression.split(" ");

	String main = stringParts[0];
	String sub = stringParts[2];

	//get the query part
	String query = expression.substring(expression.firstIndexOf("'"), expression.lastIndexOf("'"));

	if(main.equals("books"))
	{
		if(sub.equals("title")
		{
		  exp = new BookTitleExpression(query);
		}
		if(sub.equals("year")
		{
		   exp = new BookYearExpression(query);
		}
	}
	else  if(main.equals("movie"))
		  {
			//similar statements to create movie expressions
		  }

	if(exp != null)
	{
		exp.interpret(context);
	}

 }

 public static void main(String[] args)
 {
	InterpreterContext context  = new InterpreterContext("http://aws.amazon.com/");
	AmazonClient client = new AmazonClient();

	//run a query
	String result = client.interpret("books by author 'John Connolly'");

	System.out.println(result);
 }

}

I admit the example is a bit simple, and you would probably have a more intelligent context, but that should give you the idea of how this pattern works.

Watch Out for the Downsides

Efficiency is a big concern for any implementation of this pattern. Introducing your own grammar requires extensive error checking, which will be time consuming for the programmer to implement, and needs careful design in order to run efficiently at runtime. Also, as the grammar becomes more complicated, the maintainence effort is increased.

Find Out More


The classic Design Patterns: Elements of Reusable Object Oriented Software
For more practical Java examples: Head First Design Patterns.

Design Patterns Uncovered: The Facade Pattern

This article will focus on the Facade pattern. So far in our design patterns we’ve already looked at the Observer and Adapter patterns. Facade has some similarities with the Adapter, so it’s a logical next step in our series.

Facades in the Real World

Facades are all around us in the real world.  Operating systems are one such example – you don’t see all the inner workings of your computer, but the OS provides a simplified interface to use the machine. Buildings also have a facade – the exterior of the building. Wikipedia gives us a nice link between software architecture and standard architecture:

In architecture, the facade of a building is often the most important from a design standpoint, as it sets the tone for the rest of the building

So, in a nutshell, a Facade aims to make things look cleaner and more appealling.

Design Patterns Refcard
For a great overview of the most popular design patterns, DZone’s Design Patterns Refcard is the best place to start.

The Facade Pattern

Like the Adapter pattern, Facade is known as a structural pattern, as it’s used to identifying a simple way to realize relationships between entities. The definition of Facade provided in the original Gang of Four book on Design Patterns states:

Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

The diagram definition of the Facade pattern is quite simple – all you’re really doing is insulating client from the subsystem:

Facade Pattern

Like the adapter pattern, the Facade can be used to hide the inner workings of a third party library, or some legacy code.  All that the client needs to do is interact with the Facade, and not the subsystem that it is encompassing.

The following sequence diagram illustrates how the pattern is used by a client:

Facade Pattern Sequence Diagram

Where Would I Use This Pattern?

As the concept behind facade is to simplify an interface, service oriented architectures make use of the facade pattern. For example, in web services, one web service might provide access to a number of smaller services that have been hidden from the caller by the facade. Similarly, a typical pattern in OSGi bundles is to provide an interface package that is exposed to users of the bundle. All other packages are hidden from the user.

So How Does It Work In Java?

Let’s put together a simple example in Java code to illustrate the pattern. Let’s take a travel agent site for example, that allows you to book hotels and flights. We have a HotelBooker:

public class HotelBooker
{

  public ArrayList<Hotel> getHotelNamesFor(Date from, Date to)
  {
      //returns hotels available in the particular date range

  }

}

And a FlightBooker:

public class FlightBooker
{

  public ArrayList<Flight> getFlightsFor(Date from, Date to)
  {
      //returns flights available in the particular date range

  }

}

Both of these have Hotel and Flight datatypes, which the client has knowledge about. They could be provided in the same package as the Facade for example.

The TravelFacade class allows the user to get their Hotel and Flight information in one call:

public class TravelFacade
{

   private HotelBooker hotelBooker;
   private FlightBooker flightBooker; 

  public void getFlightsAndHotels(Date from, Data to)
  {
         ArrayList<Flight> flights = flightBooker.getFlightsFor(from, to);
         ArrayList<Hotel> hotels = hotelBooker.getHotelsFor(from, to);

         //process and return

   }

}

All that the client needs to worry about is the Facade class:

public class Client
{

   public static void main(String[] args)
   {
        TravelFacade facade = new TravelFacade();
        facade.getFlightsAndHotels(from, to);
   }
}

As you can see, it’s just a simple approach to encapsulating data.

Watch Out for the Downsides

By introducing the Facade into your code, you will be hardwiring subsystems into the Facade. This is fine if the subsystem never changes, but if it does, your Facade could be broken. Therefore, developers working on the subsystem should be made aware of any Facade around their code.

Find Out More


The classic Design Patterns: Elements of Reusable Object Oriented Software
For more practical Java examples: Head First Design Patterns.

Design Patterns Uncovered: The Adapter Pattern

Continuing our series of articles, taking each design pattern one by one, we move onto the Adapter pattern. This pattern is used a lot in Eclipse, allowing plug-ins to be loosely coupled, yet still be integrated into the Eclipse runtime.

Adapters in the Real World

A real world analogy always helps with the understanding of a design pattern. The best example for the adapter pattern is based around AC power adapters. Say you’re visiting Europe from the US, with your laptop, which expects a US power supply. To get your laptop plugged in, you’re going to need to get a power adapter that accepts your US plug and allows it to plug in to the European power outlet. The AC adapter knows how to deal with both sides, acting as a middleman – this is the adapter pattern.

Design Patterns Refcard
For a great overview of the most popular design patterns, DZone’s Design Patterns Refcard is the best place to start.

The Adapter Pattern

The Adapter is known as a structural pattern, as it’s used to identifying a simple way to realize relationships between entities. The definition of Adapter provided in the original Gang of Four book on Design Patterns states:

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

Let’s take a look at the classic diagram definition of  the adapter pattern:

Adapter Pattern

The Target interface defines the domain specific interface that the Client used, so the client collaborates with objects that implement the Target interface. On the other side of things, the Adaptee is the existing interface that needs adapting in order for our client to interact with it. The Adapter adapts the Adaptee to the Target interface – in other words, it translates the request from the client to the adaptee.

Let’s take a look at the interactions in a sequence diagram:

Adapter Sequence Diagram

In this example, as far as the Client is concerned it’s just calling the request method of the Target interface, which the Adapter has implemented. In the background however, the Adapter knows that to return the right result, it needs to call a different method, specificAdapteeRequest, on the Adaptee.

Note: the pattern described here is the object adapter. There is a class adapter pattern, but you need multiple inheritance to use it. Seeing as Java doesn’t support multiple inheritance, I’m going to leave this out.

Where Would I Use This Pattern?

The main use of this pattern is when a class that you need to use doesn’t meet the requirements of an interface. As mentioned before, adapters are common across Eclipse plug-ins. For a particular object to contribute to the Properties view, adapters are used display the objects data. The view itself doesn’t need to know anything about the object the it is displaying properties for.

So How Does It Work In Java?

The following example shows a simple implementation of the pattern. Consider that we have a third party library that provides sorting functionality through it’s NumberSorter class. This is our Adaptee.

/*
 * This is our adaptee, a third party implementation of a
 * number sorter that deals with Lists, not arrays.
 */
public class NumberSorter
{
   public List<Integer> sort(List<Integer> numbers)
   {
      //sort and return
      return new ArrayList<Integer>();
   }

}

Our Client deals with primitive arrays rather than Lists. For the sake of this example, lets say we can’t change the client to use Lists.

int[] numbers = new int[]{34, 2, 4, 12, 1};

Sorter sorter = new SortListAdapter();
sorter.sort(numbers);

We’ve provided a Sorter interface that expects the client input. This is our target.

//this is our Target interface
public interface Sorter
{
   public int[] sort(int[] numbers);
}
Finally, the SortListAdapter implements our target interface and deals with our adaptee, NumberSorter
public class SortListAdapter implements Sorter
{

   @Override
   public int[] sort(int[] numbers)
   {
      //convert the array to a List
      List<Integer> numberList = new ArrayList<Integer>();

      //call the adapter
      NumberSorter sorter = new NumberSorter();
      numberList = sorter.sort(numberList);

      //convert the list back to an array and return 

      return sortedNumbers;
   }

}

While this example may be overkill, it illustrates how the adapter pattern can work.

Watch Out for the Downsides

Some say that the Adapter pattern is just a fix for a badly designed system, which didn’t consider all possibilties. While this is a fair point, it is an important part of a pluggable architecture.  It can also add a level of complexity to your code, making debugging more difficult.

Find Out More


The classic Design Patterns: Elements of Reusable Object Oriented Software
For more practical Java examples: Head First Design Patterns.

Design Patterns Uncovered: The Visitor Pattern

Today we’re going to take a look at the Visitor pattern. Of all of the patterns that I’ve used so far, Visitor is by far the most powerful and convenient.

Vistors in the Real World

A real world analogy always helps with the understanding of a design pattern. One example I have seen for the Visitor pattern in action is a taxi example, where the customer calls orders a taxi, which arrives at his door. Once the person sits in, the visiting taxi is in control of the transport for that person.

Shopping in the supermarket is another common example, where the shopping cart is your set of elements. When you get to the checkout, the cashier acts as a visitor, taking the disparate set of elements (your shopping), some with prices and others that need to be weighed, in order to provide you with a total.

It’s a difficult pattern to explain in the real world, but things should become clearer as we go through the pattern definition, and take a look at how to use it in code.

Design Patterns Refcard
For a great overview of the most popular design patterns, DZone’s Design Patterns Refcard is the best place to start.

The Visitor Pattern

The Visitor is known as a behavioural pattern, as it’s used to manage algorithms, relationships and responsibilities between objects. The definition of Visitor provided in the original Gang of Four book on Design Patterns states:

Allows for one or more operation to be applied to a set of objects at runtime, decoupling the operations from the object structure.

What the Visitor pattern actually does is create an external class that uses data in the other classes. If you need to perform operations across a dispate set of objects, Visitor might be the pattern for you. The GoF book says that the Visitor pattern can provide additional functionality to a class without changing it. Let’s see how that can work, first by taking a look at the classic diagram definition of  the Visitor pattern:

Visitor Pattern

The core of this pattern is the Visitor interface. This interface defines a visit operation for each type of ConcreteElement in the object structure. Meanwhile, the ConcreteVisitor implements the operations defined in the Visitor interface. The concrete visitor will store local state, typically as it traverses the set of elements. The element interface simply defines an accept method to allow the visitor to run some action over that element – the ConcreteElement will implement this accept method.

Where Would I Use This Pattern?

The pattern should be used when you have distinct and unrelated operations to perform across a structure of objects. This avoids adding in code throughout your object structure that is better kept seperate, so it encourages cleaner code. You may want to run operations against a set of objects with different interfaces.  Visitors are also valuable if you have to perform a number of unrelated operations across the classes.

In summary, if you want to decouple some logical code from the elements that you’re using as input, visitor is probably the best pattern for the job.

So How Does It Work In Java?

The following example shows a simple implementation of the pattern in Java. The example we’ll use here is a postage system. Our set of elements will be the items in our shopping cart. Postage will be determined using the type and the weight of each item, and of course depending on where the item is being shipped to.

Let’s create a seperate visitor for each postal region. This way, we can seperate the logic of calculating the total postage cost from the items themselves. This means that our individual elements don’t need to know anything about the postal cost policy, and therefore, are nicely decoupled from that logic.

First, let’s create our general visitable  interface:

//Element interface
public interface Visitable
{
    public void accept(Visitor visitor);
}

Now, we’ll create a concrete implementation of our interface, a Book.

//concrete element
public class Book implements Visitable
{
   private double price;
   private double weight;

   //accept the visitor
   public void accept(Visitor vistor)
   {
      visitor.visit(this);
   }

   public double getPrice()
   {
      return price;
   }

   public double getWeight()
   {
      return weight;
   }
}

As you can see it’s just a simple POJO, with the extra accept method added to allow the visitor access to the element. We could add in other types here to handle other items such as CDs, DVDs or games.

Now we’ll move on to the Visitor interface. For each different type of concrete element here, we’ll need to add a visit method. As we’ll just deal with Book for now, this is as simple as:

public interface Visitor
{
   public void visit(Book book);
   //visit other concrete items
   public void visit(CD cd);
   public void visit(DVD dvd);
}

The implementation of the Vistor can then deal with the specifics of what to do when we visit a book.

public class PostageVisitor implements Visitor
{
   private double totalPostageForCart;
   //collect data about the book
    public void visit(Book book)
    {
      //assume we have a calculation here related to weight and price
      //free postage for a book over 10
      if(book.getPrice() < 10.0)
      {
         totalPostageForCart += book.getWeight() * 2;
      }
    }

    //add other visitors here
    public void visit(CD cd){...}
    public void visit(DVD dvd){...}
    //return the internal state
    public double getTotalPostage()
    {
      return totalPostageForCart;
    }
}

As you can see it’s a simple formula, but the point is that all the calculation for book postage is done in one central place.

To drive this visitor, we’ll need a way of iterating through our shopping cart, as follows:

public class ShoppingCart
{
   //normal shopping cart stuff
   private ArrayList<Visitable> items;

   public double calculatePostage()
  {
      //create a visitor
      PostageVisitor visitor = new PostageVisitor();
      //iterate through all items
      for(Visitable item: items)
      {
         item.accept(visitor);
      }
     double postage = visitor.getTotalPostage();
     return postage;

  }

}

Note that if we had other types of item here, once the visitor implements a method to visit that item, we could easily calculate the total postage.

So, while the Visitor may seem a bit strange at first, you can see how much it helps to clean up your code. That’s the whole point of this pattern – to allow you seperate out certain logic from the elements themselves, keeping your data classes simple.

Watch Out for the Downsides

The arguments and return types for the visiting methods needs to be known in advance, so the Visitor pattern is not good for situtations where these visited classes are subject to change. Every time a new type of Element is added, every Visitor derived class must be amended.

Also, it can be difficult to refactor the Visitor pattern into code that wasn’t already designed with the pattern in mind. And, when you do add your Visitor code, it can look obscure. The Visitor is powerful, but you should make sure to use it only when necessary.

Find Out More


The classic Design Patterns: Elements of Reusable Object Oriented Software
For more practical Java examples: Head First Design Patterns.

Design Patterns Uncovered: The Observer Pattern

Design patterns are one of the most valuable tools for developers. They illustrate the best design solutions that others have encountered, and allow you to apply the same principle to your own designs. More importantly, knowing design patterns gives a common vocabulary for software developers to use when talking about their designs.

In this article series, I’ll be going through each pattern and describing how it’s used and where it’s applied in the real world. To start off, I’ll be describing one of the most used design patterns, the Observer pattern.

The Observer In The Real World

Before we get into the theory and code behind the Observer, let’s take a look at a real world example, such as RSS feeds. When I want to get updates from a particular feed, I add it to my feed reader. Any time that the RSS feed has an update, it will appear in my reader automatically. This is the Observer pattern in action, a publisher/subscriber relationship with one source having many subscribers.

The Observer Pattern

Of all of the design patterns that are out there, the Observer is one that you’ve probably used already, even if you weren’t aware of it. The Observer pattern is the gold standard in decoupling – the seperation of objects that depend on each other.

The Observer is known as a behavioural pattern, as it’s used to form relationships between objects at runtime. The definition provided in the original Gang of Four book on Design Patterns states:

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Let’s take a look at the classic diagram definition of the observer:

The idea behind the pattern is simple – one of more Observers are interested in the state of a Subject and register their interest with the Subject by attaching themselves. When something changes in our Subject that the Observer may be interested in, a notify message is sent, which calls the update method in each Observer.
When the Observer is no longer interested in the Subject’s state, they can simply detatch themselves. The following sequence diagram illustrates the registration and notification flow in action.

The benefits here are quite clear. To pass data onto the observers, our subject doesn’t need to know who needs to know. Instead, everything is done through a common interface, and the notify method just calls all the objects out there that have registered their interest. This is a very powerful decoupling – meaning that any object can simply implement the Observer interface and get updates from the Subject.

Where Would I Use This Pattern?

In general, you want to use this pattern to reduce coupling. If you have an object that needs to share it’s state with others, without knowing who those objects are, the Observer is exactly what you need.

You’ll have seen, and probably used, the Observer many times if you’ve done any UI programming, especially in Swing. The whole concept of listeners is based on this pattern. The event listener is the most popular, where you register an ActionListener to a UI control, such a button, and react to action events using the actionPerformed method. In this case, the ActionListener is the Observer and the button is your Subject. As the button changes state, you can react, if you choose to, in your actionPerformed method.

The typical real world uses of the pattern all revolve around this type of event handling system.

So How Does It Work In Java?

While some patterns require you to define the interfaces that make the pattern work, the Observer is a case where Java has the work done for you already in the java.util package.

The slight difference from the classic definition is that Observable is used in place of the Subject and is implemented as a class, while the Observer interface remains the same. Let’s take a look at an implementation of the pattern with a real example. In our example, the subject will be a DataStore, with a Screen class as the observer.

First, let’s make our DataStore class observable by extending the java.util.Observable class. This means that our DataStore has all the methods and functionality available to make it a Subject, according to our pattern.

import java.util.Observable;

public class DataStore extends Observable
{

	private String data;

	public String getData()
	{
		return data;
	}

	public void setData(String data)
	{
		this.data =data;
		//mark the observable as changed
		setChanged();
	}
}

You’ll notice that we have called the setChanged() method of the Observable. This is necessary in order for the call to notify observers to send out the update. Without this set, the Observable will see no reason to send out the update.

Next, let’s create our Observer. To do this, all we need to do is implement the Observer interface which forces us to write an update method, to deal with changes in the Observable’s state.

public class Screen implements Observer {

	@Override
	public void update(Observable o, Object arg) {

		//act on the update
	}

}

Adding our Screen as an observer to the DataStore is simple:

Screen screen = new Screen();

DataStore dataStore = new DataStore();
//register observer
dataStore.addObserver(screen);

When the data changes, we want to notify all observers of this object. To do this, we just need to call the notifyObservers method when we want an update sent out

//send a notification
dataStore.notifyObservers();

As you can see it’s a really simple pattern to understand, and even easier to use thanks to the Java implementation of the pattern.

Watch Out for the Downsides

As with any piece of code, you need to be careful how you use the Observer pattern. Martin Fowler has a good list of gotchas for the observer. In his article he mentions that it can be difficult to see the path through the code, unless you are debugging. As such, you should be careful not to have chains of observers (observers acting as subjects). Also, watch out for memory leaks as the subject will hold a reference to the observer unless it has deregistered.

Find Out More


The classic Design Patterns: Elements of Reusable Object Oriented Software
For more practical Java examples: Head First Design Patterns.

If I Could Recommend Eight Books For Java Developers…

There are many books that are essential for your bookshelf if you’re a Java developer. But if I had space for just five books, which ones would I recommend? This question came into my head when I read this post about book recommendations.

Going Back To Basics


Topping the list of essentials for me has to be A Programmer’s Guide to Java Certification. I bought it before I did the certification exam years ago. Even though the edition I have refers to Java 1.4, it’s always been an excellent reference for the basics of the language. Without doubt, it’s the best book available to get going in Java.

Improving Performance


A few years back, I was working on some performance intensive features. I thought I knew threads well enough – I was wrong! This seems to be a common trend among all developers, we don’t have a great grasp on concurrency. Thankfully, Brian Goetz does and published Java Concurrency In Practice

As well as simply explaining threading you’ll find how to design and test your applications for concurrency. As multiple cores become more common this book is a must have for Java developers – especially as we dispel the myth that Java can’t be fast.

Becoming A Better Developer

The Pragmatic Programmer surprised me when I read it first. While not being specific to any language it sets out some great principles, habits and approaches for developers. I still read it every year or so to refresh. It’s been good for my own growth as a developer, and for the growth of development processes I’ve been involved in.

This book should be used in all computer courses, as it would lead to a higher percentage of graduates with a practical view on development.

 

 

I only recently read the highly acclaimed Clean Code by Robert C Martin, and that has proven to another valuable addition to my developer bookshelf. From the very beginnings of the book, you will notice common themes that lead to a poor code base.
If every developer took the time to read this book, I’m sure that software development would have a much better reputation.

Becoming a Java Expert


The second edition of Effective Java has been a welcome addition to my developer bookshelf. It has some great tips that I wouldn’t have picked up had I not read the book. And with such high praise from James Gosling, it’s a book that can’t be ignored.
“I sure wish I had had this book ten years ago. Some might think that I don’t need any Java books, but I need this one.”

The Classics

While this book is outdated in some aspects, if you can afford it, it’s a useful reference to have on your bookshelf. will always be seen as the classic book for software design.

Designing With The Future In Mind


The original GoF Design Patterns book has has set the scene for other books on patterns and design in general. Emergent Design: The Evolutionary Nature of Software Development really caught my attention recently. It has a nice concise appendix of design patterns giving a non-software analog for each, which really helps with understanding them.

It’s a great book for architects and developers to read to make designs more futureproof, stable and helps answer the question How Much Design Is Enough. It easy reading and shows how the software development industry can mature, and what you can do to improve your own practices.

 

Practical Design Patterns


The Head First series really focuses on making it easy to learn the concepts. While the original GoF book can be a bit daunting, I would certainly recommend that software developers, especially novice coders, get this book to see practical implementations of design patterns, written in Java.

 

I’m sure this isn’t the definitive list for all developers so I’d be happy to see your own opinions. What books related to software development have you found indispensable?

 

Creating An Agile Culture

I’d like to get rid of the illusion that your software development process determines if your company is ‘agile’ or not. It’s down to the culture, the mindset.

To prove this, we have to go back in time a bit – to February 2001 actually – where the Agile Manifesto was set down. It’s amazing how many people read this, and don’t pay attention to what’s said. To summarise:

  • Individuals and interactions over processes and tools
  • Working software over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan

So, point number one, says that’s it’s about the people in your team and not the process you’re using. I’ve even heard people go as far to say that you can still be agile using a Waterfall process – after thinking about it, I don’t disagree.

So, the key thing, is responsive, responsible individuals on your team who are focussed on the project outcome.
To get the whole thing right, there’s a few values that need to be maintained. Here’s my list of what those things are:

  1. Communicate
    The standing meetings concept (mostly from XP) is a good one. Don’t worry about having a meeting for the sake of it – invariably, someone will have something to say – and if there’s nothing important, the meeting will be over quickly anyway.
    Make sure that all team members give updates on what they are doing. Something you think isn’t important might be vital for someone else to know.
    Keep the test team involved (there’s a tendancy for developers to leave them out) and make sure to leverage their experience.
    Encourage desk reviews of code and design with all the stakeholders.
    Everyone should try and inject energy into the team – if everyone feels empowered, encouraged and motivated, you’ll have no problems reaching the project goals.
  2. Blame Doesn’t Fix Bugs
    Solution oriented people are much more useful than problem oriented. That’s a known fact – and it holds true in software development too. Casting blame makes people feel defensive, while being constructive makes people feel empowered. The focus needs to be on outcomes, and the team should work together to find ways to solve problems, rather that over analysising them.
  3. Fix Misunderstandings
    This could fall under the communications category, but I thought it’d be good to add in as a seperate issue. Consider, if someone misunderstands a requirement, API call or a decision, chances are someone else has also misunderstood. So, when you’re addressing one persons misunderstanding, make sure everyone else knows about the clarification too.
  4. Keep It Simple
    Ask yourself if what you’re about to do is required for the project outcome. You’ll be surprised how many times it isn’t. Don’t write documents unless you really have to.
    A simple design always takes less time to finish than a complex one, and is a lot easier for everyone in the team to understand.
    Keep things as simple as possible for as long as possible by never adding functionality before it is scheduled.
    I looked at a Standish Software Survey graph – it showed that there was 45% of features that are never used. NEVER! So I definitely don’t want to spend my time working on Never Used stuff.
    That alone is motivation for me to make sure what I work on is relevant.
  5. No Broken Windows
    Anyone that’s read The Pragmatic Programmer will be familiar with this.
    The experiment carried out goes along the lines of leaving a nice car in a dodgy neighbourhood. They come back a week later, it’s still there in perfect condition.
    So they break a window, come back the next week and the car is burnt out.
    Why? Because they started a pattern of disrespect.It’s the same in software – no one wants to be the first to start this pattern – I don’t want to be first to introduce a defect. So if we repair any “broken windows” as soon as they appear, everything will be in prestine condition for the duration of the project.
    This really is worth noting – maintain high standards in everything that you do.
  6. Embrace Change
    Decisions – in software they’re not cast in stone, they’re written in sand. Things will change, and there’s no point complaining. If something does change it’s for the good of the project outcome.
    Embrace change (as XP would recommend), or just roll with it.
    Don’t fixate on a given plan, respond to the changing environment and learn.
  7. Be Flexible
    To be truly agile, you need to be able to cross disciplines – leading, coding, testing, requirements, fixing a machine – take it all as part of your daily job. You’ll increase your own learning, and value to the company.
    Be ready to do everything!
  8. Keep Everything Releasable
    If you’re a tester this is easy to understand, if you’re not just imagine you are for a second.
    To test or check progress, you need to see output – whether it’s fully ready or not. You don’t want to be told that you have to wait a day for a build!
    Everything should be ready to pass on at any time. It’s easier for everyone involved.
    It doesn’t need to be perfect, it just needs to be transparent.
  9. The Big Picture
    Understand the business and big picture implications of all decisions.
    This may be done by a Product Owner – (this could be a committee, Requirements Engineers and Architect). If using a product owner concept, use them as a “Customer”
    People need to be reminded of this vision by the Product Owner.
    To forget what the outcome of the project needs to be is the worst type of failure.
    If we keep selling a vision, people will believe.

So there you go – my opinions on real Agility.
It’s all down to the people and their mindset. If you have a team of developers following the above values, you can use any tools/processes that you want, but you will have agility.

I originally posted this article on AgileZone.