-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.html
More file actions
507 lines (393 loc) · 23.5 KB
/
Copy pathindex.html
File metadata and controls
507 lines (393 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>TheLadders Engineering Stories</title>
<meta name="author" content="TheLadders Engineering">
<meta name="description" content="… when the Man comes around.–Johnny Cash We are happy to announce that on April 10th, TheLadders will be hosting
Eric Evans, the codifier …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://dev.theladders.com/">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="TheLadders Engineering Stories" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _sf_async_config={uid:14481,domain:"dev.theladders.com"};
(function(){
function loadChartbeat() {
window._sf_endpt=(new Date()).getTime();
var e = document.createElement('script');
e.setAttribute('language', 'javascript');
e.setAttribute('type', 'text/javascript');
e.setAttribute('src',
(("https:" == document.location.protocol) ? "https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/" : "http://static.chartbeat.com/") +
"js/chartbeat.js");
document.body.appendChild(e);
}
var oldonload = window.onload;
window.onload = (typeof window.onload != 'function') ?
loadChartbeat : function() { oldonload(); loadChartbeat(); };
})();
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15937967-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="collapse-sidebar sidebar-footer" >
<header role="banner"><hgroup>
<h1><a href="/">TheLadders Engineering Stories</a></h1>
<h2>This is how we work.</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:dev.theladders.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/ourteam">Our Team</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/2013/03/eric-evans-is-coming-to-theladders/">Eric Evans Is Coming to TheLadders</a></h1>
<p class="meta">
<time datetime="2013-03-08T10:09:00-05:00" pubdate data-updated="true">Mar 8<span>th</span>, 2013</time>
</p>
</header>
<div class="entry-content"><blockquote><p>… when the Man comes around.</p><footer><strong>–Johnny Cash</strong></footer></blockquote>
<p>We are happy to announce that on April 10th, TheLadders will be hosting
<a href="http://domainlanguage.com/about/">Eric Evans</a>, the codifier of
<a href="http://domainlanguage.com/ddd/">Domain Driven Design</a>, for the New
York City DDD Meetup group. Engineers at TheLadders have long been
following developments in the DDD community. <a href="/ourteam/kyrisarantakos/">Some</a> of
<a href="/ourteam/danielwislocki/">us</a> have already attended the DDD immersion course,
<a href="/ourteam/kylewinter/">more</a> of <a href="/ourteam/mattjankowski/">us</a> will be attending it shortly, and
our developers are regular participants in the <a href="http://www.dddnyc.org/">NYC DDD Meetup</a>.</p>
<p>For those of you who might be unfamiliar with DDD, its goal is the
design of software that creates business value. DDD guides technical
and domain experts to collaboratively create a mental model of the
central business concepts. This model is then used to drive
design. This sounds like common sense: developers work with people who
know about the business to make software that works to solve its
problems. What could be more straightforward? And yet, the complexity
inherent in the business world and software engineering make it
difficult to create software that is supple and adaptable to changing
needs. DDD provides a framework for thinking about, creating, and
communicating mental models. And that requires the learning of new
skills and ideas. It isn’t an easy process, but we have found that it
is rewarding for both the business and developers.</p>
<h1>A Little of Our Experience with DDD</h1>
<p>While creating our new website, we’ve tried to remain focused on
“communicating mental models”. One way this can be done is through
DDD’s “Intention-Revealing Interfaces”: interfaces that clearly
communicate the contract between the domain model and its
users. Judging from the vast amount of code out there, this simple
idea is counterintuitive. Our own legacy codebase is no exception. For
example:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Subscription</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'> <span class="o">...</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="n">AutoRenewFlags</span> <span class="nf">getAutoRenewFlag</span><span class="o">()</span>
</span><span class='line'> <span class="o">{</span>
</span><span class='line'> <span class="k">return</span> <span class="n">autoRenewFlag</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setAutoRenewFlag</span><span class="o">(</span><span class="n">AutoRenewFlags</span> <span class="n">autoRenewFlag</span><span class="o">)</span>
</span><span class='line'> <span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">autoRenewFlag</span> <span class="o">=</span> <span class="n">autoRenewFlag</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kt">int</span> <span class="nf">getUnsubscribeReason</span><span class="o">()</span>
</span><span class='line'> <span class="o">{</span>
</span><span class='line'> <span class="k">return</span> <span class="n">unsubscribeReason</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setUnsubscribeReason</span><span class="o">(</span><span class="kt">int</span> <span class="n">unsubscribeReason</span><span class="o">)</span>
</span><span class='line'> <span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">unsubscribeReason</span> <span class="o">=</span> <span class="n">unsubscribeReason</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>This is an example of what in DDD is called an “anemic domain
model”. The Subscription class is a key part of the domain, yet not
only does it communicate nothing to the user about its usage, it in
fact does nothing. Values can be retrieved and set, but what then? How
do I actually unsubscribe someone? What prevents me from using any
arbitrary integer for the “unsubscribe reason”? What about changing
auto-renewal to null? There is no explicit contract here, and the user
of this object is given no guidance or constraints. By contrast, we’ve
worked hard in our newer code to avoid creating anemic domain models
and instead create objects that are not only useful, but clear in
their usage. Here is another example, this time from the new
Subscription class:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">abstract</span> <span class="kd">class</span> <span class="nc">Subscription</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'> <span class="o">...</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kd">abstract</span> <span class="n">Subscription</span> <span class="nf">withAutoRenewOn</span><span class="o">();</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kd">abstract</span> <span class="n">Subscription</span> <span class="nf">withAutoRenewOff</span><span class="o">();</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kd">abstract</span> <span class="n">CanceledSubscription</span> <span class="nf">unsubscribe</span><span class="o">(</span><span class="n">UnsubscribeReason</span> <span class="n">unsubscribeReason</span><span class="o">);</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>In this case we’ve attempted to make the contract clear. Calling the
unsubscribe method actually unsubscribes the customer, returning a
CanceledSubscription. The “unsubscribe reason” is now strongly typed,
clearly communicating which values are allowed. Auto-renewal changes
yield a new immutable Subscription object, and can be chained together
with other “with*” methods to produce new subscriptions with appropriate
settings.</p>
<p>Another example of an anemic domain model, lacking an
intention-revealing interface, comes from the old Payment class in our
legacy codebase:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="nf">Payment</span><span class="o">(</span><span class="kt">int</span> <span class="n">paymentId</span><span class="o">,</span>
</span><span class='line'> <span class="kt">int</span> <span class="n">paymentActionType</span><span class="o">,</span>
</span><span class='line'> <span class="n">BigDecimal</span> <span class="n">amount</span><span class="o">,</span>
</span><span class='line'> <span class="n">String</span> <span class="n">approvalCode</span><span class="o">,</span>
</span><span class='line'> <span class="n">String</span> <span class="n">transactionReference</span><span class="o">,</span>
</span><span class='line'> <span class="kt">int</span> <span class="n">creditCardId</span><span class="o">)</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">paymentId</span> <span class="o">=</span> <span class="n">paymentId</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">paymentActionType</span> <span class="o">=</span> <span class="n">paymentActionType</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">amount</span> <span class="o">=</span> <span class="n">amount</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">approvalCode</span> <span class="o">=</span> <span class="n">approvalCode</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">creditCardId</span> <span class="o">=</span> <span class="n">creditCardId</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">transactionReference</span> <span class="o">=</span> <span class="n">transactionReference</span><span class="o">;</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>This class contains only the constructor you see here, and getters for
each of the fields created. It turns out that it’s used as a parameter
object, and nothing more. There’s no guidance as to it’s valid
construction, and no hint about its usage. Yet obviously handling
subscription payments is an important part of the subscription domain,
and we want the contracts around the model of that domain clear and
easy to understand. Here’s our attempt at accomplishing those goals in
the new codebase:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="nf">Payment</span><span class="o">(</span><span class="n">PaymentAmount</span> <span class="n">paymentAmount</span><span class="o">,</span>
</span><span class='line'> <span class="n">JobseekerId</span> <span class="n">jobseekerId</span><span class="o">,</span>
</span><span class='line'> <span class="n">PaymentActionType</span> <span class="n">paymentActionType</span><span class="o">,</span>
</span><span class='line'> <span class="n">ReportGroup</span> <span class="n">reportGroup</span><span class="o">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>The first difference is actually one that’s not visible from the code
itself. As we’ve developed the new site, we’ve agreed that all
arguments to methods or constructors are required; no passing of
nulls. If an argument is truly optional, a separate method or
constructor is added that excludes it. We want our code to be
confident, and this contract means that methods and constructors “say
what they mean and mean what they say”. In the legacy codebase, nulls
were passed liberally to and fro, and you could never be quite sure
which arguments were truly required.</p>
<p>Another change is the promotion of this class from a mere parameter
object to an active participant in the domain model:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="n">Receipt</span> <span class="nf">makeWith</span><span class="o">(</span><span class="n">PaymentMethod</span> <span class="n">method</span><span class="o">)</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'> <span class="n">method</span><span class="o">.</span><span class="na">make</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
</span><span class='line'> <span class="k">return</span> <span class="k">new</span> <span class="nf">Receipt</span><span class="o">(</span><span class="n">paymentAmount</span><span class="o">.</span><span class="na">asAmountPaid</span><span class="o">());</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kt">void</span> <span class="nf">recordWith</span><span class="o">(</span><span class="n">PaymentRecorder</span> <span class="n">paymentRecorder</span><span class="o">)</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'> <span class="n">paymentRecorder</span><span class="o">.</span><span class="na">record</span><span class="o">(</span><span class="n">paymentAmount</span><span class="o">);</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>Instead of being passed around to “manager” objects and DAOs, a
Payment object can actually make a payment and create records of
itself. It seems only natural.</p>
<p>There’s much more qto Domain Driven Design than I’ve shown here –
this post barely scratches the surface. And as a team we know we still
have much farther to go in its mastery, but the time we’ve spent in
study and practice have been well worth the effort so far.</p>
<p><a href="http://www.dddnyc.org/events/80390502/">We hope you’ll join us April 10th</a> for an illuminating evening of
presentation and discussion.</p>
</div>
</article>
<div class="pagination">
<a class="prev" href="/blog/page/2/">← Older</a>
<a href="/blog/archives">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/2013/03/eric-evans-is-coming-to-theladders/">Eric Evans Is Coming to TheLadders</a>
</li>
<li class="post">
<a href="/2013/03/riders-on-the-storm-take-a-long-holiday-let-your-children-play/">Riders on the Storm: Take a long holiday, Let your children play</a>
</li>
<li class="post">
<a href="/2013/02/mutation-testing-with-pit-a-step-beyond-normal-code-coverage/">Mutation testing with PIT: A step beyond normal code coverage</a>
</li>
<li class="post">
<a href="/2013/02/onboarding/">The Catechism of Code</a>
</li>
<li class="post">
<a href="/2013/01/new-beginnings/">New Beginnings</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating…</li>
</ul>
<a href="https://github.com/TheLadders">@TheLadders</a> on GitHub
<script type="text/javascript">
$.domReady(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'TheLadders',
count: 3,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
<section>
<h1>Latest Tweets</h1>
<ul id="tweets">
<li class="loading">Status updating…</li>
</ul>
<script type="text/javascript">
$.domReady(function(){
getTwitterFeed("TheLaddersDev", 3, false);
});
</script>
<script src="/javascripts/twitter.js" type="text/javascript"> </script>
<a href="http://twitter.com/TheLaddersDev" class="twitter-follow-button" data-show-count="false">Follow @TheLaddersDev</a>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - TheLadders Engineering -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId=212934732101925&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script type="text/javascript">
(function() {
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
})();
</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>