The Artima Developer Community
Sponsored Link

Flexibility and Complexity
A Conversation with Martin Fowler, Part IV
by Bill Venners
November 25, 2002

<<  Page 4 of 4


Designing Interfaces

Bill Venners: The way I think about design, I tend to think a lot in terms of interfaces. The literature on patterns and agile methods, Design Patterns (the Gang of Four book), Kent Beck's Extreme Programming Explained, your Refactoring book, talk a lot about code, which is both interfaces and implementations. What is the design role of thinking in terms of interfaces?

Martin Fowler: I think thinking in terms of interfaces is very fundamental. My take on the Gang of Four book is that it said more about the role of interfaces than almost any other book on object-oriented design.

Bill Venners: How's that?

Martin Fowler: Because every other book on object-oriented design might say somewhere in the book, "Oh yeah, interfaces are important." But I think the Gang of Four book put a very strong piece in the early chapters about what it means to program to an interface. And then almost every pattern in that book is about how interfaces can vary independently to implementations and the benefits of programming to an interface.

I think that's also true of extreme programming. The whole value of test-first design (test-driven development as Kent is calling it), in fact the primary driving reason of it, is because when you are writing the tests first you are thinking about the interface. Writing a test is designing the interface. When you write the test first, then implement the code, you are figuring out the interface first, then implementing the interface. First figure out the interface, then implement it. And then you have a whole bunch of automated tests that describe how the interface works.

Bill Venners: I hadn't gotten that from my reading of the literature. The way I kind of approach it is, I design the interface first, then sometimes I write the test first, sometimes write the test second, sometimes don't write the test.

Martin Fowler: Not a problem.

Bill Venners: If writing the test first kind of correlates to thinking about designing the interface, then it is kind of the same thing.

Martin Fowler: Oh yeah. But I think writing the test first speaks a lot more to many developers. It is hard to think about interfaces, but when you sit there and you say, I've got to come up with a test that's going to make this tiny little piece of functionality work. It will have you thinking, what's the nicest way to write this test? And you're thinking about the interface. It is not stated explicitly, but that's what you're doing. You're thinking about the interface. You're also doing it incrementally. You're not saying, here I've got to do this class, let's come up with the interface of this entire class and then implement it. You're saying, this class needs to have a very small piece of responsibility. Write the test for it. Come up with the interface for that as you're writing the test.

Talk Back!

Have an opinion about flexibility and reusability, refactoring, test-first programming, or interface design? Discuss this article in the News & Ideas Forum topic, Flexibility and Complexity.


Refactoring: Improving the Design of Existing Code, by Martin Fowler with Kent Beck, John Brant, William Opdyke, and Don Roberts is at at:

To Be Explicit, an article by Martin Fowler first published in IEEE Software:

Public versus Published Interfaces, an article by Martin Fowler first published in IEEE Software:

The Pragmatic Programmer: From Journeyman to Master, by Andrew Hunt and David Thomas, is at at:

IntelliJ IDEA, a Java IDE with refactoring support:

Eclipse, an open source IDE with refactoring support:

A catalog of summaries of refactorings mentioned in the book, Refactoring:

A refactoring portal maintained by Martin Fowler contains links to refactoring tools and other refactoring sites:

Martin Fowler's links to extreme programming resources:

Articles written by Martin Fowler about XP and agile methods:

Patterns of Enterprise Application Architecture, by Martin Fowler is at at:

UML Distilled: A Brief Guide to the Standard Object Modeling Language, by Martin Fowler and Kendall Scott is at at:

Planning Extreme Programming, by Kent Beck and Martin Fowler is at at:

Analysis Patterns: Reusable Object Models , by Martin Fowler is at at:

Martin Fowler's website contains many articles, book chapters, and other information from Martin:

<<  Page 4 of 4

Sponsored Links

Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use