The BDD and Design Patterns Connection

August 7, 2017 — Posted by Al Shalloway

Behavioral Driven Development is more than about doing analysis with tests, it is about setting up the implementation as well.  Design Patterns lead to a way of thinking that results in better design that BDD sets the stage for.  Design Patterns are very much misunderstood.  I explained some of this in an article called Can Patterns Be Harmful? However, most people still think of patterns only as “solutions to a recurring problem in a context.” This was a phrase used by Christopher Alexander (the architect on which design patterns are based).  However, he also said – ”At this final stage, the patterns are no longer important: the patterns have taught you to be receptive to what is real.”  What he meant was that we should attend to the forces that the patterns reconcile. 

Patterns can be thought of as existing at three levels:

1) Providing insights on a way of writing code that gets good results

2) When we get enough of these good results that have similar intent, we can say “Patterns are solutions to recurring problems in a context”

3) The thought process of creating designs based on the relationships between patterns in our problem domain

In other words, patterns can be thought of as a set of practices that result in good code quality.  When patterns of intent form we can name them.  We can also think in terms of these patterns to solve bigger designs.   What are these code qualities that create good code quality?

Seven qualities of code have proven to be very useful:

  1. Testability
  2. Encapsulation
  3. Decoupling
  4. Designing to behavior
  5. Separating use from construction
  6. Cohesion
  7. Avoiding duplication

The interested reader can learn more about these by going to Code Qualities on the Net Objectives Portal site (LinkediIn registration required).  It’s interesting to observe the relationship between these seven qualities and Behavioral Driven Development’s (BDD) Given-When-Then construct.

1. Testability is clearly achieved by using GWT since it is an actual specification of a test.

2. Encapsulation of the GWT implementation is implied since the T of GWT is about the result, not the implementation.

3. Decoupling occurs between the GWTs since each is independent of each other.

4. Designing to behavior is achieved by specifying what results we want without discussing the behavior.

5. Separating use from construction should be used in the implementations of GWT since different implementations may be used for different situations.  In other words, we should use a factory to select which implementations are needed for the different implementations required in the different situations.

6. Cohesion is achieved since the implementation of each GWT should be about the specific case involved.

7. Avoiding duplication is not achieved via GWT.  But it can be found during testing.  When duplicate tests are required we know we have duplication.  This is important because duplication is not just about duplication of code but duplication of intent.

Summation

It is important to realize that patterns are a way of thinking and a way of writing better code – not merely solutions to recurring problems in a context.  Using GWT directly results into many of the good practices that patterns espouse.  Used together can be a very powerful approach.

Al Shalloway

Subscribe to our blog Net Objectives Thoughts Blog

Share this:

About the author | Al Shalloway

Al Shalloway is the founder and CEO of Net Objectives. With over 40 years of experience, Alan is an industry thought leader in Lean, Kanban, product portfolio management, SAFe, Scrum and agile design.



        

Blog Authors

Al Shalloway
Business, Operations, Process, Sales, Agile Design and Patterns, Personal Development, Agile, Lean, SAFe, Kanban, Kanban Method, Scrum, Scrumban, XP
Cory Foy
Change Management, Innovation Games, Team Agility, Transitioning to Agile
Guy Beaver
Business and Strategy Development, Executive Management, Management, Operations, DevOps, Planning/Estimation, Change Management, Lean Implementation, Transitioning to Agile, Lean-Agile, Lean, SAFe, Kanban, Scrum
Israel Gat
Business and Strategy Development, DevOps, Lean Implementation, Agile, Lean, Kanban, Scrum
Jim Trott
Business and Strategy Development, Analysis and Design Methods, Change Management, Knowledge Management, Lean Implementation, Team Agility, Transitioning to Agile, Workflow, Technical Writing, Certifications, Coaching, Mentoring, Online Training, Professional Development, Agile, Lean-Agile, SAFe, Kanban
Ken Pugh
Agile Design and Patterns, Software Design, Design Patterns, C++, C#, Java, Technical Writing, TDD, ATDD, Certifications, Coaching, Mentoring, Professional Development, Agile, Lean-Agile, Lean, SAFe, Kanban, Kanban Method, Scrum, Scrumban, XP
Marc Danziger
Business and Strategy Development, Change Management, Team Agility, Online Communities, Promotional Initiatives, Sales and Marketing Collateral
Max Guernsey
Analysis and Design Methods, Planning/Estimation, Database Agility, Design Patterns, TDD, TDD Databases, ATDD, Lean-Agile, Scrum
Scott Bain
Analysis and Design Methods, Agile Design and Patterns, Software Design, Design Patterns, Technical Writing, TDD, Coaching, Mentoring, Online Training, Professional Development, Agile
Steve Thomas
Business and Strategy Development, Change Management, Lean Implementation, Team Agility, Transitioning to Agile
Tom Grant
Business and Strategy Development, Executive Management, Management, DevOps, Analyst, Analysis and Design Methods, Planning/Estimation, Innovation Games, Lean Implementation, Agile, Lean-Agile, Lean, Kanban