initial commit

This commit is contained in:
2026-08-16 19:03:44 +02:00
commit f9726ca9dc
215 changed files with 29489 additions and 0 deletions
@@ -0,0 +1,663 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0110)https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/ -->
<html xmlns="http://www.w3.org/1999/xhtml" class=" ybzqiqr idc0_350"><head profile="http://gmpg.org/xfn/11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="./design-by-contract-teil2_files/athena.js.Download" type="text/javascript"></script>
<script type="text/javascript">window.addEventListener('DOMContentLoaded',function(){var v=archive_analytics.values;v.service='wb';v.server_name='wwwb-app215.us.archive.org';v.server_ms=408;archive_analytics.send_pageview({});});</script>
<script type="text/javascript" src="./design-by-contract-teil2_files/bundle-playback.js.Download" charset="utf-8"></script>
<script type="text/javascript" src="./design-by-contract-teil2_files/wombat.js.Download" charset="utf-8"></script>
<script>window.RufflePlayer=window.RufflePlayer||{};window.RufflePlayer.config={"autoplay":"on","unmuteOverlay":"hidden"};</script>
<script type="text/javascript" src="./design-by-contract-teil2_files/ruffle.js.Download"></script>
<script type="text/javascript">
__wm.init("https://web.archive.org/web");
__wm.wombat("http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/","20100312070014","https://web.archive.org/","web","/_static/",
"1268377214");
</script>
<link rel="stylesheet" type="text/css" href="./design-by-contract-teil2_files/banner-styles.css">
<link rel="stylesheet" type="text/css" href="./design-by-contract-teil2_files/iconochive.css">
<!-- End Wayback Rewrite JS Include -->
<title>build broken » Design by Contract jetzt auch mit C# Teil 2</title>
<meta name="generator" content="WordPress abc">
<meta name="theme" content="Mandigo 1.41">
<link rel="stylesheet" href="./design-by-contract-teil2_files/style.css" type="text/css" media="screen">
<style type="text/css">
body {
font-family: Arial, Sans-Serif;
background-color: #44484F;
}
a {
font-weight: bold;
}
.narrowcolumn .entry, .widecolumn .entry {
line-height: 1.4em;
}
.inline-widgets #wp-calendar caption, .blogname, .blogdesc {
font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;
}
.blogname {
font-size: 4em;
margin-top: 15px;
}
.posttitle, #comments, #respond .title, #respond.pre27, #trackbacks {
font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;
}
.commentlist li, #commentform input, #commentform textarea {
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
}
#commentform p {
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
}
.sidebars {
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
}
#page {
width: 987px;
}
#header {
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/images/header-1024.png);
height: 243px;
width: 987px;
}
#headerimg {
height: 226px;
width: 961px;
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/schemes/orange/images/head-1024.jpg) bottom center no-repeat;
}
#main {
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/images/bg-1024.png);
width: 957px;
}
#footer {
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/images/foot-1024.png);
}
.post {
text-align: justify;
background: #FAFAFA;
border: 1px solid #EEEEEE;
}
#footer {
width: 987px;
}
.sidebars {
background: #EEEEEE;
border: 1px solid #DDDDDD;
}
#sidebar1 .sidebars {
width: 210px;
}
#sidebar2 .sidebars {
width: 210px;
}
.entry img {
float: none;
}
.sidebars li {
list-style-image: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/schemes/orange/images/star.gif);
}
.commentlist {
}
.commentlist li {
list-style: none;
}
#wp-calendar {
margin: 0 !important; margin-top: -1.5em;
}
#wp-calendar caption {
margin-top: -1.4em;
}
/* dirty fix for the event calendar plugin */
div#wp-calendar .nav {
margin: 0;
}
/* end dirty fix */
.datestamp div {
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Sans-Serif;
}
.cal3 {
}
.pages {
text-align: right;
}
.pages ul li.has_sub {
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/images/icons/bullet_arrow_right.png) no-repeat center right;
}
.head_overlay {
background: url(https://web.archive.org/web/20100312070014im_/http://blog.aztec-project.org/wp-content/themes/mandigo/images/head_overlay.png);
}
</style>
<link rel="stylesheet" href="./design-by-contract-teil2_files/scheme.css" type="text/css" media="screen">
<link rel="alternate" type="application/rss+xml" title="build broken RSS Feed" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/feed/">
<link rel="pingback" href="https://blog.aztec-project.org/xmlrpc.php">
<link rel="alternate" type="application/rss+xml" title="build broken » Design by Contract jetzt auch mit C# Teil 2 Kommentar Feed" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/feed/">
<script type="text/javascript" src="./design-by-contract-teil2_files/comment-reply.js.Download"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://blog.aztec-project.org/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://blog.aztec-project.org/wp-includes/wlwmanifest.xml">
<link rel="index" title="build broken" href="https://blog.aztec-project.org/">
<link rel="start" title="Umsetzung des Plug-In-Patterns" href="https://blog.aztec-project.org/2009/06/05/umsetzung-des-plug-in-patterns/">
<link rel="prev" title="Clean Code Teil 2" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/04/clean-code-teil-2/">
<link rel="next" title="MVP mit WinForms (Model-View-Presenter)" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/12/02/mvp-mit-winforms-model-view-presenter/">
<link rel="canonical" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/">
<script type="text/javascript" src="./design-by-contract-teil2_files/jquery.js.Download"></script>
<script type="text/javascript" src="./design-by-contract-teil2_files/jquery.ifixpng.js.Download"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<style type="text/css">
.entry img, .entry embed, .entry object { max-width: 880px; width: expression(this.clientWidth > 880 ? 880 : true); }
.entry img { height: auto; }</style>
</head>
<body><!-- BEGIN WAYBACK TOOLBAR INSERT -->
<script>__wm.rw(0);</script>
<div id="wm-ipp-base" lang="en" style="display: block; direction: ltr;"><template shadowrootmode="closed"><div id="wm-ipp" style="position:fixed;left:0;top:0;right:0;" class="">
<div id="donato" style="position:relative;width:100%;">
<div id="donato-base">
<iframe id="donato-if" src="https://archive.org/includes/donate.php?as_page=1&amp;platform=wb&amp;referer=https%3A//web.archive.org/web/20100312070014/http%3A//blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" scrolling="no" frameborder="0" style="width:100%; height:100%">
</iframe>
</div>
</div><div id="wm-ipp-inside">
<div id="wm-toolbar" style="position:relative;display:flex;flex-flow:row nowrap;justify-content:space-between;">
<div id="wm-logo" style="/*width:110px;*/padding-top:12px;">
<a href="https://web.archive.org/web/" title="Wayback Machine home page"><img src="https://web.archive.org/_static/images/toolbar/wayback-toolbar-logo-200.png" srcset="/_static/images/toolbar/wayback-toolbar-logo-100.png, /_static/images/toolbar/wayback-toolbar-logo-150.png 1.5x, /_static/images/toolbar/wayback-toolbar-logo-200.png 2x" alt="Wayback Machine" style="width:100px" border="0"></a>
</div>
<div class="c" style="display:flex;flex-flow:column nowrap;justify-content:space-between;flex:1;">
<form class="u" style="display:flex;flex-direction:row;flex-wrap:nowrap;" target="_top" method="get" action="https://web.archive.org/web/submit" name="wmtb" id="wmtb"><input type="text" name="url" id="wmtbURL" value="http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" onfocus="this.focus();this.select();" style="flex:1;" autocomplete="off"><input type="hidden" name="type" value="replay"><input type="hidden" name="date" value="20100312070014"><input type="submit" value="Go">
</form>
<div style="display:flex;flex-flow:row nowrap;align-items:flex-end;">
<div class="s" id="wm-nav-captures" style="flex:1;"><a class="t" href="https://web.archive.org/web/*/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" title="See a list of every capture for this URL">11 captures</a><div class="r" title="Timespan for captures of this URL">8 Nov 2009 - 7 May 2021</div></div>
<div class="k">
<a href="https://web.archive.org/web/20030701000000/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" id="wm-graph-anchor">
<div id="wm-ipp-sparkline" title="Explore captures for this URL" style="position: relative">
<canvas id="wm-sparkline-canvas" width="750" height="27" border="0"></canvas>
<div class="yt" style="display: none; width: 25px; height: 27px; left: 175px;"></div><div class="mt" style="display: none; width: 2px; height: 27px; left: 188px;"></div></div>
</a>
</div>
</div>
</div>
<div class="n">
<table>
<tbody>
<!-- NEXT/PREV MONTH NAV AND MONTH INDICATOR -->
<tr class="m">
<td class="b" nowrap="nowrap"><a href="https://web.archive.org/web/20091109094541/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/" title="09 Nov 2009"><strong>Nov</strong></a></td>
<td class="c" id="displayMonthEl" title="You are here: 07:00:14 Mar 12, 2010">Mar</td>
<td class="f" nowrap="nowrap"><a href="https://web.archive.org/web/20140804121108/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2" title="04 Aug 2014"><strong>Aug</strong></a></td>
</tr>
<!-- NEXT/PREV CAPTURE NAV AND DAY OF MONTH INDICATOR -->
<tr class="d">
<td class="b" nowrap="nowrap"><a href="https://web.archive.org/web/20091109094541/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/" title="09:45:41 Nov 09, 2009"><img src="https://web.archive.org/_static/images/toolbar/wm_tb_prv_on.png" alt="Previous capture" width="14" height="16" border="0"></a></td>
<td class="c" id="displayDayEl" style="width:34px;font-size:22px;white-space:nowrap;" title="You are here: 07:00:14 Mar 12, 2010">12</td>
<td class="f" nowrap="nowrap"><a href="https://web.archive.org/web/20140804121108/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2" title="12:11:08 Aug 04, 2014"><img src="https://web.archive.org/_static/images/toolbar/wm_tb_nxt_on.png" alt="Next capture" width="14" height="16" border="0"></a></td>
</tr>
<!-- NEXT/PREV YEAR NAV AND YEAR INDICATOR -->
<tr class="y">
<td class="b" nowrap="nowrap">2009</td>
<td class="c" id="displayYearEl" title="You are here: 07:00:14 Mar 12, 2010">2010</td>
<td class="f" nowrap="nowrap"><a href="https://web.archive.org/web/20140804121108/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2" title="04 Aug 2014"><strong>2014</strong></a></td>
</tr>
</tbody>
</table>
</div>
<div class="r" style="display:flex;flex-flow:column nowrap;align-items:flex-end;justify-content:space-between;">
<div id="wm-btns" style="text-align:right;height:23px;">
<span class="xxs">
<div id="wm-save-snapshot-success">success</div>
<div id="wm-save-snapshot-fail">fail</div>
<a id="wm-save-snapshot-open" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#" title="Share via My Web Archive" style="display: none;">
<span class="iconochive-web"></span>
</a>
<a href="https://archive.org/account/login.php" title="Sign In" id="wm-sign-in" style="display: inline-block;">
<span class="iconochive-person"></span>
</a>
<span id="wm-save-snapshot-in-progress" class="iconochive-web" style="display: none;"></span>
</span>
<a class="xxs" href="http://faq.web.archive.org/" title="Get some help using the Wayback Machine" style="top:-6px;"><span class="iconochive-question" style="color:rgb(87,186,244);font-size:160%;"></span></a>
<a id="wm-tb-close" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#close" style="top:-2px;" title="Close the toolbar"><span class="iconochive-remove-circle" style="color:#888888;font-size:240%;"></span></a>
</div>
<div id="wm-share" class="xxs">
<a href="https://web.archive.org/web/20100312070014/http://web.archive.org/screenshot/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" id="wm-screenshot" title="screenshot" style="visibility: hidden;">
<span class="wm-icon-screen-shot"></span>
</a>
<a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#" id="wm-video" title="video">
<span class="iconochive-movies"></span>
</a>
<a id="wm-share-facebook" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#" data-url="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/" title="Share on Facebook" style="margin-right:5px;" target="_blank"><span class="iconochive-facebook" style="color:#3b5998;font-size:160%;"></span></a>
<a id="wm-share-twitter" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#" data-url="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/" title="Share on Twitter" style="margin-right:5px;" target="_blank"><span class="iconochive-twitter" style="color:#1dcaff;font-size:160%;"></span></a>
</div>
<div style="padding-right:2px;text-align:right;white-space:nowrap;">
<a id="wm-expand" class="wm-btn wm-closed" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#expand"><span id="wm-expand-icon" class="iconochive-down-solid"></span> <span class="xxs" style="font-size:80%;">About this capture</span></a>
</div>
</div>
</div>
<div id="wm-capinfo" style="border-top:1px solid #777;display:none; overflow: hidden">
<div id="wm-capinfo-notice" source="api"></div>
<div id="wm-capinfo-collected-by">
<div style="background-color:#666;color:#fff;font-weight:bold;text-align:center">COLLECTED BY</div>
<div style="padding:3px;position:relative" id="wm-collected-by-content">
<div style="display:inline-block;vertical-align:top;width:50%;">
<span class="c-logo" style="background-image:url(https://archive.org/services/img/alexacrawls);"></span>
Organization: <a style="color:#33f;" href="https://archive.org/details/alexacrawls" target="_new"><span class="wm-title">Alexa Crawls</span></a>
<div style="max-height:75px;overflow:hidden;position:relative;">
<div style="position:absolute;top:0;left:0;width:100%;height:75px;background:linear-gradient(to bottom,rgba(255,255,255,0) 0%,rgba(255,255,255,0) 90%,rgba(255,255,255,255) 100%);"></div>
Starting in 1996, <a href="http://www.alexa.com/">Alexa Internet</a> has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the <a href="http://web.archive.org/">Wayback Machine</a> after an embargo period.
</div>
</div>
<div style="display:inline-block;vertical-align:top;width:49%;">
<span class="c-logo" style="background-image:url(https://archive.org/services/img/alexa_web_2010)"></span>
<div>Collection: <a style="color:#33f;" href="https://archive.org/details/alexa_web_2010" target="_new"><span class="wm-title">alexa_web_2010</span></a></div>
<div style="max-height:75px;overflow:hidden;position:relative;">
<div style="position:absolute;top:0;left:0;width:100%;height:75px;background:linear-gradient(to bottom,rgba(255,255,255,0) 0%,rgba(255,255,255,0) 90%,rgba(255,255,255,255) 100%);"></div>
this data is currently not publicly accessible.
</div>
</div>
</div>
</div>
<div id="wm-capinfo-timestamps">
<div style="background-color:#666;color:#fff;font-weight:bold;text-align:center" title="Timestamps for the elements of this page">TIMESTAMPS</div>
<div>
<div id="wm-capresources" style="margin:0 5px 5px 5px;max-height:250px;overflow-y:scroll !important"></div>
<div id="wm-capresources-loading" style="text-align:left;margin:0 20px 5px 5px;display:none"><img src="https://web.archive.org/_static/images/loading.gif" alt="loading"></div>
</div>
</div>
</div></div></div><link rel="stylesheet" type="text/css" href="./design-by-contract-teil2_files/banner-styles.css"><link rel="stylesheet" type="text/css" href="./design-by-contract-teil2_files/iconochive.css"><div class="wb-autocomplete-suggestions "></div></template>
</div><div id="wm-ipp-print">The Wayback Machine - https://web.archive.org/web/20100312070014/http://blog.aztec-project.org:80/2009/11/05/design-by-contract-teil-2/</div>
<script type="text/javascript">//<![CDATA[
__wm.bt(750,27,25,2,"web","http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/","20100312070014",1996,"/_static/",["/_static/css/banner-styles.css?v=S1zqJCYt","/_static/css/iconochive.css?v=3PDvdIFv"], false);
__wm.rw(1);
//]]></script>
<!-- END WAYBACK TOOLBAR INSERT -->
<div id="page">
<div id="header" class="png">
<div id="headerimg">
<h1 class="blogname" id="blogname"><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/">build broken</a></h1><span class="blogname text-stroke-br">build broken</span><span class="blogname text-stroke-bl">build broken</span><span class="blogname text-stroke-tr">build broken</span><span class="blogname text-stroke-tl">build broken</span>
<h6 class="blogdesc" id="blogdesc">but we can fix it! Sometimes :)</h6><span class="blogdesc text-stroke-br">but we can fix it! Sometimes :)</span><span class="blogdesc text-stroke-bl">but we can fix it! Sometimes :)</span><span class="blogdesc text-stroke-tr">but we can fix it! Sometimes :)</span><span class="blogdesc text-stroke-tl">but we can fix it! Sometimes :)</span>
<ul class="pages png head_overlay">
<li class="page_item"><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/">Home</a></li>
<li class="page_item page-item-2"><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/about/" title="About">About</a></li>
</ul>
</div>
</div>
<div id="main" class="png">
<table>
<tbody><tr>
<td id="content" class="widecolumn">
<div class="navigation">
<div class="alignleft">«&nbsp;<a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/04/clean-code-teil-2/" rel="prev">Clean Code Teil 2</a></div>
<div class="alignright"><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/12/02/mvp-mit-winforms-model-view-presenter/" rel="next">MVP mit WinForms (Model-View-Presenter)</a>&nbsp;»</div>
</div>
<div class="post" id="post-801">
<div class="postinfo">
<div class="datestamp">
<div>
<span class="cal1 cal1x">Nov</span>
<span class="cal2">05</span>
<span class="cal3">2009</span>
</div>
</div>
<span class="switch-post">
<a href="javascript:toggleSidebars();" class="switch-sidebars"><img src="./design-by-contract-teil2_files/bullet_sidebars_hide.png" alt="" class="png"></a><a href="javascript:togglePost(801);" id="switch-post-801"><img src="./design-by-contract-teil2_files/bullet_toggle_minus.png" alt="" class="png"></a>
</span>
<h2 class="posttitle"><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/" rel="bookmark" title="Permanent Link: Design by Contract jetzt auch mit C# Teil 2">Design by Contract jetzt auch mit C# Teil 2</a></h2>
<small>
Geschrieben von <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/author/chi/" title="Artikel von Christina Hirth">Christina Hirth</a> in <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/category/architektur/" title="Alle Artikel in Architektur ansehen" rel="category tag">Architektur</a>, <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/category/clean-code-developing/" title="Alle Artikel in Clean Code Developing ansehen" rel="category tag">Clean Code Developing</a>, tags: <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/tag/architektur/" rel="tag">Architektur</a>, <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/tag/clean-code/" rel="tag">Clean Code</a>, <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/tag/unit-tests/" rel="tag">Unit-Tests</a> </small>
</div>
<div class="entry">
<p>Der vorherige DbC-Artikel ist ziemlich “abstrakt” ausgefallen, es haben einfach Beispiele gefehlt. Das möchte ich hiermit nachholen.</p>
<p>Erstens muss man die IDE anpassen: im März kommt .NET 4.0 raus und da wird Design by Contract mitgeliefert. Man kann das Konzept aber jetzt schon anwenden, wenn man die <a href="https://web.archive.org/web/20100312070014/http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" target="_blank">Assembly</a> zusätzlich installiert. Danach muss man die dll referenzieren und im Eigenschaftenfenster des Projektes im neuen Tab <i>Code Contracts</i> das Runtime Checking einstellen.</p>
<p>Jetzt zum Code: Nehmen wir eine ganz einfache Klasse <code>Bill</code> deren Objekte mit einem <code>IRepository</code> gespeichert bzw. geladen werden.</p>
<div style="font-family: Courier New; font-size: 9pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;<span style="color: blue;">using</span> System.Diagnostics.Contracts;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;<span style="color: blue;">namespace</span> ContractsPrototyp</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;{</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Bill</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">int</span> Id { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> Number { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">double</span> Value { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IRepository</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Bill</span> GetBill(<span style="color: blue;">string</span> number);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;15</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> SaveBill(<span style="color: #2b91af;">Bill</span> bill);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;16</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Die Kontrakte kann man in den einzelnen Methoden oder für eine ganze Klasse schreiben (unter dem Attribut <code>ContractInvariantMethode</code>) aber ich finde am schönsten, dass man die auch auslagern kann: durch eine gegenseitige Markierung können Kontrakt-Klassen und Interfaces als “Paare” definiert werden:</p>
<div style="font-family: Courier New; font-size: 9pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">ContractClass</span>(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">RepositoryContracts</span>))]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IRepository</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Bill</span> GetBill(<span style="color: blue;">string</span> number);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;15</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> SaveBill(<span style="color: #2b91af;">Bill</span> bill);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;16</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;17</span>&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">ContractClassFor</span>(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">IRepository</span>))]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;18</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">RepositoryContracts</span>:<span style="color: #2b91af;">IRepository</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;19</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;20</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">Bill</span> GetBill(<span style="color: blue;">string</span> number)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;21</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;22</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Contract</span>.Requires(!<span style="color: blue;">string</span>.IsNullOrEmpty(number));</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;23</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">null</span>;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;24</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;25</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;26</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> SaveBill(<span style="color: #2b91af;">Bill</span> bill)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;27</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;28</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Contract</span>.Ensures(bill.Id &gt; 0);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;29</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;30</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Eine Vorbedingung wird mit <code>Contract.Requires</code> und eine Nachbedingung mit <code>Contract.Ensures</code> definiert. Beide Methoden bekommen boolische Ausdrücke. Diese Ausdrücke müssen frei von Seiteneffekten sein. </p>
<p>Die eigentliche Implementierung der Klasse schaut dann so aus:</p>
<div style="font-family: Courier New; font-size: 9pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;31</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Repository</span>:<span style="color: #2b91af;">IRepository</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;32</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;33</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">Bill</span> GetBill(<span style="color: blue;">string</span> nummer)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;34</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;35</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">//Würde das Objekt aus Datenhaltung laden</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;36</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">Bill</span>();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;37</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;38</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;39</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> SaveBill(<span style="color: #2b91af;">Bill</span> bill)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;40</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;41</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">//Würde das Objekt speichern und ihm eine Id zuweisen</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;42</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (BillIsValid( bill )) bill.Id++;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;43</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;44</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;45</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">bool</span> BillIsValid(<span style="color: #2b91af;">Bill</span> bill)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;46</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;47</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> !<span style="color: blue;">string</span>.IsNullOrEmpty(bill.Nummer);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;48</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;49</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Woher können wir wissen, dass das funktioniert? Es ist einfach, wir schreiben ein Paar Tests dazu!<br>
Bei Kontraktverletzung wird eine Exception geworfen. Um diese und dadurch die genaue Verletzung überprüfen zu können braucht man etwas Workaround:</p>
<div style="font-family: Courier New; font-size: 9pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;55</span>&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">TestFixture</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;56</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">BillTests</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;57</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;58</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: #2b91af;">IRepository</span> m_repository;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;59</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">string</span> m_message;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;60</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;61</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">SetUp</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;62</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Setup()</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;63</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;64</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_repository = <span style="color: blue;">new</span> <span style="color: #2b91af;">Repository</span>();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;65</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_message = <span style="color: blue;">string</span>.Empty;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;66</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Contract</span>.ContractFailed += ( sender, e ) =&gt;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;67</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;68</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.SetUnwind();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;69</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_message = e.Message;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;70</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;71</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Danach sind die Tests dann einfach:</p>
<div style="font-family: Courier New; font-size: 9pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;73</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;74</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Laden_mit_leerer_Nummer_verletzt_Kontrakt()</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;75</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;76</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;77</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">try</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;78</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;79</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_repository.GetBill( <span style="color: blue;">null</span> );</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;80</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;81</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">catch</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;82</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;83</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">//Nichts </span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;84</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;85</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;86</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That( m_message, <span style="color: #2b91af;">Is</span>.EqualTo( <span style="color: #a31515;">"Precondition failed: !string.IsNullOrEmpty(number)"</span> ) );</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;87</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;88</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;89</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;90</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Speichern_Rechnung_ohne_Nummer_verletzt_Kontrakt()</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;91</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;92</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;93</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">try</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;94</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;95</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_repository.SaveBill( <span style="color: blue;">new</span> <span style="color: #2b91af;">Bill</span>{Value = 25} );</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;96</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;97</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">catch</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;98</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;99</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">//Nichts </span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;100</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;101</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;102</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That( m_message, <span style="color: #2b91af;">Is</span>.EqualTo( <span style="color: #a31515;">"Postcondition failed: bill.Id &gt; 0"</span> ) );</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;103</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Ich hoffe, das Beispiel ist ausführlich genug, um die Vorteile von DbC zu highlighten. <a href="https://web.archive.org/web/20100312070014/http://www.lieser-online.de/blog/" target="_blank">Stefan</a>, vielen dank noch mal für den Artikel, ich habe mich natürlich von dir inspirieren lassen.</p>
<p><a href="https://web.archive.org/web/20100312070014/http://dotnet-kicks.de/kick/?url=http%3a%2f%2fblog.aztec-project.org%2f2009%2f11%2f05%2fdesign-by-contract-teil-2%2f" target="_blank"><img src="./design-by-contract-teil2_files/KickItImageGenerator.ashx" alt="kick it on dotnet-kicks.de" border="0"></a></p>
<p class="postmetadata alt clear">
<small>
Geschrieben am Donnerstag, 5. November 2009 um 9:51 am und ist zu finden in <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/category/architektur/" title="Alle Artikel in Architektur ansehen" rel="category tag">Architektur</a>, <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/category/clean-code-developing/" title="Alle Artikel in Clean Code Developing ansehen" rel="category tag">Clean Code Developing</a>. Du kannst die Antworten zu diesem Thema verfolgen unter <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/feed/">RSS 2.0</a> feed. Du kannst <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#respond">Antwort</a>, oder <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/trackback/" rel="trackback">trackback</a> von deiner Seite.
</small>
</p>
</div>
</div>
<div id="respond">
<div class="title">Hinterlasse einen Kommentar</div>
<div class="cancel-comment-reply">
<small><a rel="nofollow" id="cancel-comment-reply-link" href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/2009/11/05/design-by-contract-teil-2/#respond" style="display:none;">Click here to cancel reply</a></small>
</div>
<form action="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/wp-comments-post.php" method="post" id="commentform">
<input type="hidden" name="comment_post_ID" value="801" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
<p><input type="text" name="author" id="author" value="" size="22" tabindex="1">
<label for="author"><small>Name (benötigt)</small></label></p>
<p><input type="text" name="email" id="email" value="" size="22" tabindex="2">
<label for="email"><small>E-mail (wird nicht veröffentlicht) (benötigt)</small></label></p>
<p><input type="text" name="url" id="url" value="" size="22" tabindex="3">
<label for="url"><small>Webseite</small></label></p>
<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
<p>
<input name="submit" type="submit" id="submit" tabindex="5" value="Kommentar absenden">
<input type="hidden" name="comment_post_ID" value="801">
</p>
<p style="clear: both;" class="subscribe-to-comments">
<input type="checkbox" name="subscribe" id="subscribe" value="subscribe" style="width: auto;">
<label for="subscribe">Notify me of followup comments via e-mail</label>
</p>
<br class="clear">
</form>
</div>
<script type="text/javascript">
<!-- // <![CDATA[
jQuery(document).ready(function() {
if (jQuery('#trackbacklist li').length == 1)
jQuery('#trackbacks, #trackbacklist').hide();
jQuery('li.comment>div>*').filter(':not(.comment-author, .comment-meta)').wrap('<div class="comment"><\/div>');
jQuery('.comment-author').before('<span class="switch-post"><a href="#"><img src="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/wp-content/themes/mandigo/images/icons/bullet_toggle_minus.png" alt="" class="png" /><\/a><\/span>');
});
// ]]> -->
</script>
</td>
<script src="./design-by-contract-teil2_files/Loader_37820.js.Download" type="text/javascript"></script></tr>
</tbody></table>
</div>
<div id="footer" class="png">
<p>
Unterstützt von <a href="https://web.archive.org/web/20100312070014/http://wordpress.org/">WordPress</a>, <a href="https://web.archive.org/web/20100312070014/http://www.onehertz.com/portfolio/wordpress/" target="_blank" title="WordPress themes">Mandigo theme</a> by tom.
<br><a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/feed/"><img src="./design-by-contract-teil2_files/rss_s.gif" alt=""> Einträge (RSS)</a>
und <a href="https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/comments/feed/"><img src="./design-by-contract-teil2_files/rss_s.gif" alt=""> Kommentare (RSS)</a>.
</p>
</div>
</div>
<script type="text/javascript">
<!-- // <![CDATA[
jQuery(document).ready(function() {
jQuery('#rssicon, #searchsubmit').hover(
function() { this.src = this.src.replace('.gif','_hover.gif'); },
function() { this.src = this.src.replace('_hover.gif','.gif'); }
);
jQuery('.entry img[align=left]' ).addClass('alignleft' );
jQuery('.entry img[align=right]').addClass('alignright');
if (jQuery.browser.msie) {
if (/^[56]/.test(jQuery.browser.version)) {
jQuery.ifixpng('https://web.archive.org/web/20100312070014/http://blog.aztec-project.org/wp-content/themes/mandigo/images/1x1.gif');
jQuery('body, .png').ifixpng();
jQuery('.commentlist.pre27 .avatar').height(36);
}
}
jQuery('p:has(.dropcap)').append('<br class="clear"/>');
togglePost = function(id) {
if (!id) return;
icon = jQuery('#switch-post-'+ id +' img');
icon.attr('src', /minus/.test(icon.attr('src')) ? icon.attr('src').replace('minus', 'plus') : icon.attr('src').replace('plus', 'minus'));
jQuery('#post-'+ id +' .entry').animate({ height: 'toggle', opacity: 'toggle' }, 1000);
}
jQuery('.switch-post img').bind('click', function() {
id = jQuery(this).parents('li').attr('id').replace(/[^\d]+-/, '');
icon = jQuery('#comment-'+ id +' .switch-post img');
src = icon.attr('src');
icon.attr('src', /minus/.test(src) ? src.replace('minus', 'plus') : src.replace('plus', 'minus'));
jQuery('#comment-'+ id +' div.comment').animate({ height: 'toggle', opacity: 'toggle' }, 1000);
return false;
});
toggleSidebars = function() {
icon = jQuery('.switch-sidebars img');
icon.attr('src', /hide/.test(icon.attr('src')) ? icon.attr('src').replace('hide', 'show') : icon.attr('src').replace('show', 'hide'));
jQuery('.sidebars').animate({ width: 'toggle', height: 'toggle', padding: 'toggle', border: 'toggle' }, 1000);
}
jQuery('.widgettitle, .linkcat *:first, .wpg2blockwidget h3').click(function() {
jQuery(this).siblings().animate({ height: 'toggle', opacity: 'toggle' }, 1000);
}).css({cursor: 'n-resize'});
jQuery.each(['tl','tr','bl','br'],function() {
jQuery('#blogname').after('<span class="blogname text-stroke-'+ this +'">'+ jQuery('#blogname a').html() +'<\/span>');
jQuery('#blogdesc').after('<span class="blogdesc text-stroke-'+ this +'">'+ jQuery('#blogdesc' ).html() +'<\/span>');
});
jQuery('#header .page_item:has(ul)').addClass('has_sub, png');
jQuery('#header .page_item').hover(
function() {
ul = jQuery(this).find('>ul');
if (ul.hasClass('sliding')) return;
a = jQuery(this).find('>a');
if (jQuery(this).parent().hasClass('pages')) {
y = a.position().top + a.height();
x = a.position().left + a.width() - ul.width();
}
else {
y = jQuery(this).position().top - 5;
x = jQuery(this).parent().width();
}
jQuery(this)
.find('>ul')
.css({left:x, top:y})
.addClass('sliding')
.slideDown(300, function() { jQuery(this).removeClass('sliding'); });
},
function() {
jQuery(this)
.find('>ul')
.addClass('sliding')
.slideUp(800, function() { jQuery(this).removeClass('sliding').hide(); });
}
);
jQuery('.commentlist li:even').addClass('alt');
});
// ]]> -->
</script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://web.archive.org/web/20100312070014/https://ssl." : "https://web.archive.org/web/20100312070014/http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./design-by-contract-teil2_files/ga.js.Download" type="text/javascript"></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9511047-1"); pageTracker._trackPageview(); } catch(err) {}</script>
<div data-lastpass-root="" style="position: absolute !important; top: 0px !important; left: 0px !important; height: 0px !important; width: 0px !important;"><template shadowrootmode="closed"><div style="position: absolute; height: 100vh; width: 100vw; z-index: 2147483647; border-radius: 4px; top: 0px; left: 0px; max-height: 0px; max-width: 280px; min-width: auto;"><iframe data-lastpass-infield="true" allow="clipboard-write" src="chrome-extension://hdokiejnpimakedhajhdlcegeplioahd/webclient-infield.html" style="border: none; height: 100%; width: 100%;"></iframe></div></template></div></body></html>