← All articles

Curly Braces Column: The Design Phase in Agile Development

When it comes to the design of agile projects, the goal is to keep everything as simple as possible, while encouraging experimentation.

Curly Braces - Eric J. Bruno

When you form a startup business, it’s a good strategy to spend money slowly, with the goal of generating revenue quickly. This is also a great one-line summary of the agile method of software development. If time is your currency, spend it on only the most important tasks, and get something into production early to serve your users. This is well understood. But I still often hear the question, “Where does the software design phase fit into the agile process?” This is the topic we’ll explore, especially as it relates to Java development.

Extreme Programming

With two or three week sprints, it may seem challenging to find time for proper software architecture and design. To answer this challenge, I turn to a precursor of agile: Extreme Programming, as described in the book of the same name, written by Kent Beck. In it, Beck suggests a design strategy with goals that are aligned with both the process and the overall project goals. As far as I can see, agile is in agreement with this strategy. By the way, check out this fascinating interview with Beck, conducted by Andrew Binstock a few years ago.

Just as it’s a myth that there’s little to no planning with the agile development process, it’s a myth that agile doesn’t account for design. For example, I’ve been part of more planning and retrospective meetings with agile than with any other process. Agile has enabled me to continuously think about and consider software design with each sprint. This is quite the opposite than waterfall, where you only consider design once, early in the process.

The notion of “sprint zero”, to me, is another myth. Taking an arbitrary amount of time at the beginning of a project to design or build a backlog by definition isn’t a sprint, and runs counter to agile. It’s effectively water-scrum-fall, a compromise. There’s a better way.

First, Focus on Simplicity

Some things are complex by nature, but often complexity has simplicity at its base. The theory for design in agile is to have just enough design to meet your immediate goals. I believe in this approach, but I’ll admit there is a risk: technical debt can accumulate. There may be sprints where a concerted, collaborative effort is needed to make larger design decisions. However, it’s important to ensure that you’re always doing just the amount of design that’s needed. Here are some strategies to employ, some general, some Java-specific, that help.

A Continuous Design Strategy

Overall, it’s better to have a design strategy that carries through to each sprint. The strategy should enforce design concepts that are in line with the project goals, and which are easily communicated to team members. I’m in favor of small bouts of design with each sprint to continuously improve the project structure. However, this is not an ad hoc process. Elements of a good design strategy should be reinforced with each sprint, such as:

  • Reduce dependencies: changes are localized and their potential adverse effects limited.
  • Consider cross-cutting facilities: grow common code as more features and components are added over time.
  • Abstraction: add only as needed.
    • Interesting side story: in the early days of the IBM PC, if IBM identified the need for someone to begin a new role, instead of hiring just one person, they would start a whole new department in anticipation of growing demand [Too Blue!, Dennis Andrews].
  • Choose simplicity: for current and future needs, go with simple designs that are easily communicated.
  • Collaboration: communicate intent as you design and code for each sprint. If you cannot easily explain what you plan, consider a simpler approach.
  • Define tests: stories should include user requirements, new feature description, and detailed directions on how to test them. After all, if you cannot describe how to test something, how can you be sure you’re properly describing what is to be built? Usually when you describe the test process, you consider how to implement the feature accurately. The result will be a design that’s complete, but also concise.

Agile, Design, and You!

Good software design is key to long term project success and team morale. But what specific Java development needs to be considered?

Experimentation

Your agile process needs to account for experimentation. Not on every sprint, perhaps, but certainly throughout the development lifecycle. For example, the Java ecosystem is rich and you may need to consider the use of one open source package among many. This can include choices between NoSQL databases, or an entirely different storage paradigm. To make this decision, you’ll need to try them. You might need a sprint to conduct this experiment.

However, the design decision to build your own NoSQL database for future flexibility is likely not the best use of time. Whereas past development practices stressed designing for future possibilities, agile doesn’t support this. Something unanticipated may come along, like the rise in graph databases, which better suit your application and data. If you built your own NoSQL database, switching means you have wasted all that effort. Or worse, you may delay the move to a graph database, perhaps a superior choice, due to a desire to maintain your investment.

Design By Contract

Java Interfaces are used to define contracts, this is known to most Java developers. They serve as a layer of abstraction, as they help break dependencies between discrete classes. In other words, if you write your code to interfaces, you can change the implementing classes without affecting those that use them. This is known as interface decoupling, and is directly in line with the agile’s rule of simplicity, with a goal of limiting side-effects of code changes.

For example, say you are implementing an automated Barista for a very busy coffee shop. There are different types of beans to use, and different brewing methods depending on the order. You can write the Barista class to use different classes directly, each representing the different coffee beans and makers. It is better to abstract the implementations through the use of interfaces: CoffeeBean and CoffeeMaker.

Although the details within the classes are different, they each implement the same set of methods. Therefore, the right classes can be supplied to the Barista constructor, shown in bold text below:

public class Barista {  
    CoffeeBean coffeeBeans \= null;  
    CoffeeMaker coffeeMaker \= null;

    public Barista(CoffeeBean beans, CoffeeMaker maker) {  
        // …  
    }

    public boolean brew() {  
        coffeeMaker.brew( coffeeBeans );  
    }  
}

// …

Barista barista \= new Barista(  
    new EspressoBeans(),  
    new EspressoMaker() );

barista.brew();

The result is a system that’s easy to extend, sprint by sprint, to automate the creation of new coffee drinks.

Acyclic dependencies

Even interface decoupling can result in risky dependencies, especially when you’re building software with small, rapid, changes. For example, say you have Java packages A, B, and C, where package A has dependencies on packages B and C, and package B has a dependency on package C (see Figure 1). In this scenario, if package C later adds a dependency on package D, which in turn has a dependency on package B, you have a cyclic dependency between them.

Figure 1 - Cyclic redundancy in Java packages

This scenario may seem contrived, but it’s more common than you might think. It can result in build issues and side effects when making changes to a package and its classes. It can easily sneak up on you in an agile project involving many developers, but proper design effort applied at every sprint will help to avoid it.

Dependency Inversion Principle

One strategy to break cyclic dependencies is the dependency inversion principle (DIP). With it, you create the right level of abstraction to avoid highly-couple classes, yet allow them to be used together in ways that make sense. Specifically, the principle says:

  • High-level components should not import from lower-level components
  • Abstractions hide details
  • Use interfaces

In the example discussed here, the familiar topic of coffee is used. In this case, we revisit the CoffeeBean interface from the earlier code example. However, the DIP is important when you consider how CoffeeBean objects are used. They can be ground, brewed, or even just plain eaten. Sticking with the traditional, you will need a CoffeeMaker object that uses CoffeeBean objects. Since there can be different types of coffee makers, this is an interface also.

Figure 2 - The dependency inversion principle, with strict relationship rules, avoids cyclic dependencies

With DIP, it’s important to keep the relationships proper. For example, although CoffeeMakers depend on CoffeeBeans, CoffeeBeans should be written with no knowledge of types of different CoffeeMakers. Nor should beans be partial to how they’re roasted, ground, and otherwise prepared.

Scalability Through Tiers

Following the simple design strategies so far will help you design for scale later, only when you need it. With interfaces and DIP, you can more easily insert tiers within your code base as growth requires it without much rework. For example, early in the implementation of a web application, you may choose Java Server Pages that write directly to a database. Quickly, you find it’s better to have a thin data tier to abstract your storage choice. As usage grows, you may add another tier to offload transaction processing, and so on (see Figure 3).

Figure 3 - An example of a typical multi-tiered Web application

I find with a distributed architecture, such as components spread across tiers, using a form of messaging middleware helps. It allows you to reduce dependencies and remove tight coupling through the use of anonymous publish-subscribe messaging, asynchronous communication, and reliability. You can use REST, Java Message Service, WebSockets, a cloud service, or an Edge protocol such as MQTT, for example. This helps you design, code, and deploy components independently, increasing your agility. You can learn more about tiered software design here.

Conclusion and Learning More

You can follow an agile development process yet still have time to do proper software design. Instead of completing large swaths of design work up front, you continually perform just enough design with each sprint, for the problems to be solved at that moment. But as you’ve seen here, there’s still a need for a long-term design strategy, and the Java design practices presented help in the long term.

To learn more about agile software design, the sources mentioned are excellent resources. For more Java-specific design advice, there are many resources, such as the use of Data Access Objects, Behavior-Driven Development, and many other topics published in Java Magazine over the years.

Keep reading

More articles

  1. On this site12 min read

    HTML5 Server-Sent Events with Micronaut, Revisited

    EventPost, formerly MessageServer, is a simple, reliable messaging server built on Micronaut's support for HTML5 server-sent events, with queues and publish/subscribe topics over plain HTTP. The new version runs on Micronaut 5 and Java 26, stores queued messages off the Java heap in NoHeapDB, and fixes bugs that only showed up under load.

  2. On this site34 min read

    Building a Zero-GC Database in Java: Adventures in Off-Heap Storage

    NoHeapDB keeps data in process, in the same JVM, but stores it completely outside the Java heap and without relying on JNI. The first version did this with ByteBuffer.allocateDirect(). It uses MemorySegment and Arena from Java's Foreign Function and Memory (FFM) API. A store can live in memory or survive a restart as memory-mapped files. Either way, the GC never sees the stored data.

  3. blogs.oracle.com

    Curly Braces Column: Writing SOLID Java Code

    Following the Robert C. Martin's five principles of SOLID object-oriented design (OOD)can make you a better Java developer.