You are on page 1of 4

www.computer.

org/software

Driven to … Discovering Your Design Values


Rebecca J. Wirfs-Brock

Vol. 24, No. 1


January/February 2007

This material is presented to ensure timely dissemination of scholarly and technical


work. Copyright and all rights therein are retained by authors or by other copyright
holders. All persons copying this information are expected to adhere to the terms
and constraints invoked by each author's copyright. In most cases, these works
may not be reposted without the explicit permission of the copyright holder.

© 2007 IEEE. Personal use of this material is permitted. However, permission to reprint/republish this material for advertising or promotional purposes or

for creating new collective works for resale or redistribution to servers or lists, or to reuse any copyrighted component of this work in other works must be

obtained from the IEEE.

For more information, please see www.ieee.org/portal/pages/about/documentation/copyright/polilink.html.


design
Editor: Rebecca J. Wirfs-Brock ■ Wirfs-Brock Associates ■ rebecca@wirfs-brock.com

Driven to … Discovering
Your Design Values
Rebecca J. Wirfs-Brock

There will be variations of everything forever. … Ideas don’t disappear. They change form,
they merge with other ideas. —Bob Frankston, coinventor of VisiCalc

T
oday we have design or development ap- sign approaches into two camps: those that fo-
proaches that are, for example, responsi- cus first on structure and those that focus first
bility driven (RDD), test driven (TDD), on action (or responsibilities or behaviors). We
behavior driven (BDD), domain driven argued that designers who first focus only on an
(DDD), and model driven (MDD). Not object’s structure fail to maximize encapsula-
all thought leaders in software develop- tion. Thinking too early about structure makes
ment have been “driven”—Bertrand Meyer, for it too easy for implementation details to bleed
example, invented Design by Contract. But into class interfaces.
whether “driven” or not, these We contrasted two approaches for designing
approaches all emphasize a core a RasterImage class that represented a rectan-
set of values and principles gular grid of pixels. (We wrote this paper when
around which practices, tech- raster technology was new, and at the time we
niques, and tools have emerged. both worked at Tektronix, a leading provider of
A thoughtful designer should be graphics workstations.) With a data-first ap-
able to pick and choose among proach, we started defining our RasterImage
practices without losing their class by declaring the image data structure and
essence. But not all practices are then adding methods to retrieve and set the im-
congruent. After stewing in this age and query its dimensions. Voila!—a class
alphabet soup for years, I’m where form and function were inextricably in-
keen on exposing the common and complemen- tertwined. The pixel grid data structure wasn’t
tary threads that are interwoven among various considered a private implementation detail.
design practices. Next, we demonstrated how a designer could
think differently about the problem by asking,
Responsibility-driven design “What actions could this object be responsible
So how can you integrate various practices for?” and “What information should it share
without watering them down or muddling your with others?” This led us to first define opera-
thinking with too many considerations? It’s cer- tions for our RasterImage class to scale and
tainly easy if you have one belief system with rotate the image and access pixel values. The in-
one small set of coherent values and practices ternal image representation, which we didn’t
that guide your work. In 1989, Brian Wilkerson specify until after we’d defined the interface,
and I authored the paper “Object-Oriented De- was considered a private detail.
sign: A Responsibility-Driven Approach.”1 For By consciously assigning most objects action-
better or worse, we started the trend of tagging oriented responsibilities, you can design even
design approaches as “driven.” To make our seemingly data-centric objects to perform some
point, we oversimplistically divided object de- actions as well as encapsulate structural details.

0740-7459/07/$20.00 © 2007 IEEE January/February 2007 IEEE SOFTWARE 9


DESIGN

Hiding that structure makes those de- grammers write test fixtures that use Design by Contract
tails easier to change. To us it seemed these behavioral specifications to test In contrast, Design by Contract
that the order in which a designer con- the code. (DbC) has roots in formal specifica-
siders things profoundly affects the re- As TDD practices have grown, new tions. To specify how they expect sys-
sulting design—even for a class as variants of them, along with newer test- tem elements to interact, designers
straightforward as RasterImage. To ing frameworks, have emerged. Users of write contracts specifying what must be
quote Samuel Alexander, the philoso- jMock use mocks that mimic unimple- true before a module can begin (precon-
pher, “An object is not first imagined or mented behaviors to drive out an appro- ditions), what must be preserved during
thought about and then expected … but priate distribution of responsibilities its execution (invariants), and what it
in being actively expected it is imagined among collaborators.5 They don’t think guarantees to be true after it completes
as future and in being willed it is that it’s just about testing, either. Mock- (postconditions). You could specify con-
thought.” ing lets you incrementally design and tracts for components, services, or even
Since those early days I’ve added the build software, hypothesizing and refin- individual methods. However, in prac-
notion of role stereotypes,2 acknowledg- ing your ideas as you go. tice, most contracts are written at the
ing that not all objects are active. Infor- method level because existing program-
mation holders—objects with responsi- Behavior-driven design ming languages and tools support work
bility for maintaining data—have a place BDD is another subtle refinement of at that level. Writing contracts is easier
in a design, too. But encapsulating their TDD. BDD proponents firmly believe if the languages and tools you use sup-
private details is important. that how you talk about what you’re do- port them and you have good examples
ing influences how you work. The focus to emulate. The Eiffel language inte-
Test-driven design is on writing small behavior specifica- grates contract support into the lan-
RDD evolved in the highly interactive tions to drive out the appropriate design. guage and runtime environment; most
world of Smalltalk development, where As Dave Astels puts it, “A major differ- other object-oriented languages don’t.
developers routinely designed a little, ence is vocabulary. Instead of subclass- Before looking at Contract4J, a
coded a little, and tested a little in short ing TestCase [as you would do using DbC tool for Java, I thought that spec-
cycles. The delightful tension of cycling an xUnit framework], you subclass Con- ifying contracts for languages without
between imagining what an object might text. Instead of writing methods that built-in support would be clunky.
do, building it, and then refining your start with test, you start them with However, using aspect technology,
ideas and cycling through your design should.”6 Testing, to BDD proponents, Contract4J automatically weaves as-
again can lead to deep insights. This has connotes verifying code after it’s built. pect-specific contract tests, which are
led agile-programming thought leaders Instead, they want to encourage incre- specified in method comments, into
to promote test-driven development mental design by writing small specifica- your running code. Contracts specified
practices. Test-driven design emphasizes tions, then implementing code that this way leave method code unclut-
deciding on an interface and then writ- works according to spec. tered with assertion statements and
ing code to test that interface, before im- leave a nice documentation trail of
plementing code to make the interface how methods should be invoked.
pass the test. If you choose to, you could apply
In Test-Driven Development by Ex- TDD practices to understand your
ample, Martin Fowler claims that TDD classes’ behaviors and then add contracts
“gives you this sense of keeping just one to methods whose behaviors you want
ball in the air at once, so you can con- verified at runtime. But I suspect these
centrate on that ball properly and do a two communities differ considerably in
really good job with it.”3 With a design- their thinking. Some TDD proponents
test-code-reflect-refactor rhythm, good want to discourage after-the-fact verifica-
code emerges alongside well-designed tion, which to them seems antithetical to
interfaces.
Linda Crispin explains that TDD isn’t
Does every method designing for quality. But adding con-
tracts does tighten up how you use
really about testing.4 Instead, it’s a prac- warrant a contract? classes, theoretically making it easier to
tice that gets you thinking about as Probably not. Methods catch errors before they propagate.
many aspects of a feature as you can be- When you change your design,
fore you code it. With frameworks such that don’t cause side sometimes contracts will naturally
as Fit and Fitnesse, TDD has extended effects probably don’t change, too. But once your design ideas
beyond its initial focus on just develop-
ers to enable nontechnical people to
need contracts. settle down, you can finalize or add
contractual details. But does every
write concrete examples of inputs and method warrant a contract? Probably
expected results in tabular form. Pro- not. Methods that don’t cause side ef-

10 IEEE SOFTWARE w w w . c o m p u t e r. o r g / s o f t w a r e
DESIGN

H
fects probably don’t need contracts. But ow you design should be based on Object-Oriented Programming, Systems, Lan-
I know I’d certainly find it easier to use your principles and values. Al- guages, and Applications (OOPSLA 89), ACM
Press, 1989, pp. 71–75.
class libraries if contract specifications though a big division exists between 2. R. Wirfs-Brock, “Characterizing Classes,”
were part of their documentation even those who believe the act of coding is IEEE Software, Mar./Apr. 2006, pp. 9–11.
if they weren’t validated at runtime. what validates the design and those who 3. M. Fowler, Test-Driven Development by Ex-
ample, Addison-Wesley, 2003.
don’t, you can learn many things about 4. L. Crispin, “Driving Software Quality: How
Domain-driven design good design from each. My mantra has Test-Driven Development Impacts Software
What about incorporating DDD always been, “Be open to new ideas and Quality,” IEEE Software, Nov./Dec. 2006, pp.
70–71.
ideas into your design practice? Accord- techniques that make me a better de- 5. S. Freeman et al., “Mock Roles Not Objects,”
ing to Eric Evans, DDD isn’t a technol- signer.” I side with Canadian politician Companion to 19th Ann. ACM SIGPLAN
Conf. Object-Oriented Programming, Sys-
ogy or methodology but “a way of Dan Miller, who proclaims, “You know, tems, Languages, and Applications (OOPSLA
thinking and a set of priorities, aimed at we have our differences, everybody 04), ACM Press, 2004, pp. 236–246; www.
accelerating software projects that have does, honest, real differences, but I do jmock.org/oopsla2004.pdf.
6. D. Astels, “A New Look at Test-Driven Devel-
to deal with complicated domains” believe strongly that we as neighbors are opment,” http://blog.daveastels.com/files/BDD
(www.domainlanguage.com/ddd/ drawn together far more than we’re dri- _Intro.pdf.
index.html). A central activity in DDD is ven apart.”
searching for the language that experts
use to talk about the problem and then References
literally reflecting that language in classes 1. R. Wirfs-Brock and B. Wilkerson, “Object- Rebecca J. Wirfs-Brock is president of Wirfs-Brock
Oriented Design: A Responsibility-Driven Ap- Associates and an adjunct professor at Oregon Health & Science
and services in a domain layer. Eric be- proach,” Proc. 1989 ACM SIGPLAN Conf. University. Contact her at rebecca@wirfs-brock.com.
lieves that, “If developers don’t realize
that changing code changes the model,
then their refactoring will weaken the
model rather than strengthen it.” Creat-
ing a domain model is intricately tied to
IEEE Pervasive
expressing it in working code. Domain-
driven design is an active, ongoing
process of expressing this domain lan-
Computing
guage in code. delivers the latest peer-reviewed developments in
pervasive, mobile, and ubiquitous computing to
Model-driven design developers, researchers, and educators who
In contrast, adherents of MDD want to keep abreast of rapid technology
(some call it model-driven engineering change. With content that’s accessible and
to avoid the Object Management Group useful today, this publication acts as a catalyst
trademarked term) first develop a plat- for progress in this emerging field, bringing
form-independent model of their system
together the leading experts in such areas as
(usually in UML or a domain-specific
language) before translation tools trans-
form the model into platform-specific • Hardware technologies
code. MDD practitioners strive to • Software infrastructure
clearly represent system concepts and
behaviors with the goal of producing an • Sensing and interaction
abstract model, not working code (the with the physical world
translation tools do that for them). This
view of model building followed by • Graceful integration
transformation probably causes the of human users
great divide between MDD practition-
ers and other design schools—even
• Systems considerations,
though they share many common de- including scalability,
sign values. After recently listening to
and talking with several well-known
Subscribe security, and privacy
MDD proponents who were discussing Now!
what constitutes well-designed classes,
methods, and components, I found my-
self nodding in agreement with many of V I S I T www.computer.org/pervasive
their design guidelines.

January/February 2007 IEEE SOFTWARE 11

You might also like