-
Notifications
You must be signed in to change notification settings - Fork 0
/
97-things-11-domain-lang.html
104 lines (104 loc) · 7.56 KB
/
97-things-11-domain-lang.html
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
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="keywords" content="97-things, domain language" />
<title>برداشت ۱۱ — به زبان دامنه</title>
<link href="https://cdn.rawgit.com/rastikerdar/vazir-font/v18.0.0/dist/font-face.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/static/default.css">
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; position: absolute; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; }
pre.numberSource a.sourceLine:empty
{ position: absolute; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: absolute; left: -5em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<article class="markdown-body">
<header>
<h1 class="title">برداشت ۱۱ — به زبان دامنه</h1>
</header>
<!--# برداشت ۱۱ — به زبان دامنه -->
<p>تکه کد زیر را در نظر بگیرید:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw">if</span> (courseIdByStudentId</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"> .<span class="fu">get</span>(s.<span class="fu">getId</span>())</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"> .<span class="fu">contains</span>(c.<span class="fu">getId</span>())) </a>
<a class="sourceLine" id="cb1-4" data-line-number="4">{ <span class="kw">... </span>}</a></code></pre></div>
<p>خیلی مهم نیست و خیلی تلاش نکنید. تا به حال چند بار همچنین کدی را خوانده تا بتوانید تغییری در آن دهید؟</p>
<p>بعد از کمی خواندن و جستجو در کد معلوم میشود که این تکه نگاشت دروس گذراندهشده توسط یک دانشجو میباشد. دوباره بعد از کمی تأمل مشخص میشود که گزاره <code>if</code> در این کد برای تشخیص این که آیا دانشجویی، درسی را گذرانده است یا نه، به کار رفته است.</p>
<p>یعنی به شکل ساده، در ابتدا، هدف این بوده است: آیا دانشجوی دال درس سین را گذرانده است؟</p>
<p>اما چرا این سؤال ساده به این شکل خیلی پیچیده در کد ظاهر شده است؟</p>
<p><strong>اول</strong> این یک ویژگی رابط (API Feature) است که فراموش شده است:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="kw">interface</span> Student {</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"> <span class="dt">boolean</span> <span class="fu">takenCourse</span>(Course c);</a>
<a class="sourceLine" id="cb2-3" data-line-number="3">}</a></code></pre></div>
<p>بسیاری از اوقات سرعت تولید قربانی طراحی درست میشود. مراقب باشیم چنین ویژگیهای منطقی و لازم برای محصول/سرویس را از قلم نیندازیم.</p>
<p><strong>دوم</strong> ساختمانهای داده خیلی پیشرفتهتر از سالهای قبل در اختیار ماست. زمانی بوده است که داشتن کلاس/شی و یا ساختمانهای داده با توجه به محدودیتهای سختافزاری و حافظه کار سختی بوده است. ما دیگر در آن دوران نیستم همان طور که آیندگان ما ممکن است در مورد ساختماندادههای زمان حاضر پیشرفتهای دیگری داشته باشند. استفاده از <code>Map</code> در کاربرد بالا در واقع درست است اما در پس تعریف درست ویژگی باعث آسیب میشود.</p>
<p>به زبان دامنه (Domain Language) سیستمی که روی آن کار میکنیم آشنا شویم و آن را به درستی در واسطهای سیستم استفاده کنیم. در مثال ما، زبان دامنه، زبان یک سیستم آموزشی شامل دانشجو و درس میباشد.</p>
<div id="disqus_thread"></div><script>var disqus_config=function(){this.page.url=window.location.href;this.page.identifier=window.location.pathname.replace(/\//g, '_');};(function(){var d=document, s=d.createElement('script');s.src = 'https://narmnevis.disqus.com/embed.js';s.setAttribute('data-timestamp', +new Date());(d.head || d.body).appendChild(s);})();</script><noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</article>
</body>
</html>