<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.smart-java.nl &#187; patterns</title>
	<atom:link href="http://blog.smart-java.nl/blog/index.php/category/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smart-java.nl/blog</link>
	<description>Ordina J-Technologies - Java Blog</description>
	<lastBuildDate>Wed, 05 May 2010 20:06:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Immutable lists</title>
		<link>http://blog.smart-java.nl/blog/index.php/2010/03/26/immutable-lists/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2010/03/26/immutable-lists/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 15:03:51 +0000</pubDate>
		<dc:creator>Pieter van der Meer</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Java language]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=1048</guid>
		<description><![CDATA[The last couple of years there is more and more talk about concurrency. One of the main issues is the access data from the various threads that you have running.
Brian Goetz has a simple statement on how to solve this:  Use immutable objects where ever possible. Although true it is not always as simple to [...]]]></description>
			<content:encoded><![CDATA[<p>The last couple of years there is more and more talk about concurrency. One of the main issues is the access data from the various threads that you have running.</p>
<p>Brian Goetz has a simple statement on how to solve this:  <em>Use immutable objects where ever possible. </em>Although true it is not always as simple to implement your data structures immutable. especially when you are working with Collections (List/Set/Map).</p>
<p>Making the collection variable immutable is easy,<br />
<span id="more-1048"></span></p>
<pre class="brush: java">class finalSet {
  private final Set theSet;
  public finalSet(Set theSet) {
    this.theSet = theSet;
  }

  public Set getSet() {
    return this.theSet;
  }
}</pre>
<p>With this it is not possible the change the value of the Set parameter. But when retrieving the Set with <em>getSet </em>you are still able to modify the content of the set.  This effectively means that the set you attempted to make immutable is still mutable.</p>
<p>The documentation of the <a href="http://java.sun.com/javase/6/docs/technotes/guides/collections/overview.html">Collections Framework</a> does not provide an answer on how to make the collection immutable. they speak just a little about the class <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">Collections<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">. </span></span></p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Taken from the documentation page:</span></span></p>
<blockquote><p>The general-purpose implementations support all of the <em>optional operations</em> in the collection interfaces, and have no restrictions on the elements they may contain. They are unsynchronized, but the <code>Collections</code> class contains static factories called <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html#synchronizedCollection(java.util.Collection)"><em>synchronization wrappers</em></a> that may be used to add synchronization to many unsynchronized collections. All of the new implementations have <em>fail-fast iterators</em>, which detect illegal concurrent modification, and fail quickly and cleanly (rather than behaving erratically).</p></blockquote>
<p>What they say there is a Collections class that does all kind of things for you, mainly synchronization, but do not really say what else it can do for you. As you might guess it provides with methods to make you list immutable!</p>
<p>Take a look at the <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html">Collections javadoc</a> (without explicitly searching for this class its hard to find).<br />
It gets interesting when you scroll down to the methods that start with</p>
<pre>unmodifiable</pre>
<p>. For all the base interface from the <a href="http://java.sun.com/javase/6/docs/technotes/guides/collections/overview.html">Collections Framework</a> there is a method to make it unmodifiable. hey wait a second: unmodifiable aint that the same as immutable? To my humble opinion it does. So Java does provide a out of the box solution to make a collection immutable!</p>
<p>this code snippet proves that it works:</p>
<pre class="brush: java">import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.HashSet;

/**
 * Simple Unit test for immutability
 */
public class ListTest {

    /**
     * The actual testing for a List
     */
    @Test (expected = UnsupportedOperationException.class)
    public void immutableList() {
        //Create a simple mutable list
        List mutableList = new ArrayList();
        mutableList.add("A");
        mutableList.add("B");
        //Make this immutable
        List immutableList = Collections.unmodifiableList(mutableList);

        //Try and set the value of an element in the list
        immutableList.set(1, "X");
    }

    /**
     * The actual testing for a Set
     */
    @Test (expected = UnsupportedOperationException.class)
    public void immutableSet() {
        //Create a mutable set
        Set mutableSet = new HashSet();
        mutableSet.add("A");
        mutableSet.add("B");
        //Change it to immutable
        Set immutableSet = Collections.unmodifiableSet(mutableSet);

        //Try and add an element to it.
        immutableSet.add("X");
    }
}</pre>
<p>When you run the unit tests both the tests will succeed.</p>
<p><strong>Conclusion</strong>:<br />
making a list immutable ain&#8217;t that hard <img src='http://blog.smart-java.nl/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Just be aware i say nothing about the elements in the list, they must be immutable as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2010/03/26/immutable-lists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Temporale data – deel 4: bitemporale collections</title>
		<link>http://blog.smart-java.nl/blog/index.php/2009/12/07/temporale-data-%e2%80%93-deel-4-bitemporale-collections/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2009/12/07/temporale-data-%e2%80%93-deel-4-bitemporale-collections/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 11:36:20 +0000</pubDate>
		<dc:creator>gnoij</dc:creator>
				<category><![CDATA[Algemeen]]></category>
		<category><![CDATA[Java language]]></category>
		<category><![CDATA[Tools/Frameworks]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[bitemporal pattern]]></category>
		<category><![CDATA[temporale data]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=551</guid>
		<description><![CDATA[Het is alweer enige tijd geleden dat ik heb geschreven over temporale patterns. In dit deel wil ik het bitemporale pattern uitbreiden met bitemporale collections. Werd met de bitemporale property nog een enkele property historisch gemaakt, in dit deel maken we een lijst historisch. Dat wil zeggen dat er meerdere elementen van een historische lijst [...]]]></description>
			<content:encoded><![CDATA[<p>Het is alweer enige tijd geleden dat ik heb geschreven over <a href="http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%e2%80%93-deel-1-de-concepten/">temporale patterns</a>. In dit deel wil ik het <a href="http://blog.smart-java.nl/blog/index.php/2008/12/22/temporale-data-%e2%80%93-deel-3-het-bitemporale-pattern/">bitemporale pattern</a> uitbreiden met bitemporale collections. Werd met de bitemporale property nog een enkele property historisch gemaakt, in dit deel maken we een lijst historisch. Dat wil zeggen dat er meerdere elementen van een historische lijst tegelijkertijd geldig kunnen zijn.</p>
<p>De klasse <code>BiTemporalObject</code> uit het derde deel blijft hetzelfde. En naast de <code>BiTemporalProperty</code> voor enkelvoudige historische relaties krijgen we nu ook een klasse <code>BiTemporalCollection</code> voor meervoudige historische relaties.</p>
<p><strong>BiTemporalCollection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BiTemporalCollection <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">List</span> alleHistorischeVersies <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> BiTemporalCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getActueleVersies<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> peilDatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">select</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peilDatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> voegActueleVersieToe<span style="color: #009900;">&#40;</span>BiTemporalObject actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>actueleVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;actueleVersie is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> wijzigActueleVersie<span style="color: #009900;">&#40;</span>BiTemporalObject nieuweVersie, BiTemporalObject oudeVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nieuweVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nieuweVersie is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>oudeVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;oudeVersie is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        beeindigVorigeVersie<span style="color: #009900;">&#40;</span>nieuweVersie, oudeVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>nieuweVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> beeindigVorigeVersie<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> BiTemporalObject nieuweVersie, <span style="color: #000000; font-weight: bold;">final</span> BiTemporalObject oudeVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        BiTemporalObject afTeVoerenVersie <span style="color: #339933;">=</span> zoekActueleVersie<span style="color: #009900;">&#40;</span>oudeVersie, nieuweVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, nieuweVersie.<span style="color: #006633;">getOpvoerTijdstip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>afTeVoerenVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Geen oude actuele versie gevonden!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        beeindigVersie<span style="color: #009900;">&#40;</span>afTeVoerenVersie, nieuweVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, nieuweVersie.<span style="color: #006633;">getOpvoerTijdstip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beeindig<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> BiTemporalObject actueleVersie, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        BiTemporalObject afTeVoerenVersie <span style="color: #339933;">=</span> zoekActueleVersie<span style="color: #009900;">&#40;</span>actueleVersie, einddatum, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>afTeVoerenVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Geen oude actuele versie gevonden!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        beeindigVersie<span style="color: #009900;">&#40;</span>afTeVoerenVersie, einddatum, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beeindig<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">List</span> afTeVoerenVersies <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">select</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                BiTemporalObject versie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span> versie.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        CollectionUtils.<span style="color: #006633;">forAllDo</span><span style="color: #009900;">&#40;</span>afTeVoerenVersies, <span style="color: #000000; font-weight: bold;">new</span> Closure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                beeindigVersie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> input, einddatum, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> beeindigVersie<span style="color: #009900;">&#40;</span>BiTemporalObject versie, <span style="color: #003399;">Date</span> einddatum, <span style="color: #003399;">Date</span> registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        BiTemporalObject kopieVersie <span style="color: #339933;">=</span> versie.<span style="color: #006633;">kopieer</span><span style="color: #009900;">&#40;</span>einddatum, registratieTijdstip<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>kopieVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> BiTemporalObject zoekActueleVersie<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> BiTemporalObject actueleVersie, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> peildatum, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                BiTemporalObject versie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span> versie.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> versie.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>De wijzigingen ten opzichte van de <code>BiTemporalProperty</code> uit het vorige deel zijn dat er nu niet één maar meer versies tegelijkertijd geldig kunnen zijn (<code>getActueleVersies</code>) en dat we versies kunnen toevoegen (<code>voegActueleVersieToe</code>) en kunnen wijzigen (<code>wijzigActueleVersie</code>). Bij deze laatste methode we de te wijzigen versie meegeven, zodat deze beëindigd kan worden en de nieuwe versie toegevoegd wordt. Ook  kunnen we alle versies van de collection beëindigen (<code>beeindig</code>) of een enkele versie (die dan weer aan de methode meegegeven moet worden).</p>
<h3>Een voorbeeld</h3>
<p>In dit voorbeeld wordt het voorbeeld uit deel 3 uitgebreid met een manager (zelf ook een werknemer), die meerdere werknemers onder zich heeft. </p>
<p><strong>Manager</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Manager <span style="color: #000000; font-weight: bold;">extends</span> Werknemer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> BiTemporalCollection werknemers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BiTemporalCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Manager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Manager<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> naam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>naam<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> voegWerknemerToe<span style="color: #009900;">&#40;</span>Werknemer werknemer, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">voegActueleVersieToe</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WerknemerRelatie<span style="color: #009900;">&#40;</span>werknemer, ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getTeManagenWerknemers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">List</span> relaties <span style="color: #339933;">=</span> getWerknemerRelaties<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CollectionUtils.<span style="color: #006633;">transform</span><span style="color: #009900;">&#40;</span>relaties, <span style="color: #000000; font-weight: bold;">new</span> Transformer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> transform<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>WerknemerRelatie<span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getWerknemer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> relaties<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getTeManagenWerknemers<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">List</span> relaties <span style="color: #339933;">=</span> getWerknemerRelaties<span style="color: #009900;">&#40;</span>registratieTijdstip, peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CollectionUtils.<span style="color: #006633;">transform</span><span style="color: #009900;">&#40;</span>relaties, <span style="color: #000000; font-weight: bold;">new</span> Transformer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> transform<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>WerknemerRelatie<span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getWerknemer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> relaties<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getWerknemerRelaties<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">getActueleVersies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getWerknemerRelaties<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">getVersieOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> wijzigWerknemer<span style="color: #009900;">&#40;</span>Werknemer nieuweWerknemer, Werknemer oudeWerknemer, <span style="color: #003399;">Date</span> wijzigingsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        WerknemerRelatie nieuweRelatie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WerknemerRelatie<span style="color: #009900;">&#40;</span>nieuweWerknemer, wijzigingsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        WerknemerRelatie oudeRelatie <span style="color: #339933;">=</span> bepaalWerknemerRelatie<span style="color: #009900;">&#40;</span>oudeWerknemer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">wijzigActueleVersie</span><span style="color: #009900;">&#40;</span>nieuweRelatie, oudeRelatie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> WerknemerRelatie bepaalWerknemerRelatie<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Werknemer werknemer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>WerknemerRelatie<span style="color: #009900;">&#41;</span>CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">getActueleVersies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>WerknemerRelatie<span style="color: #009900;">&#41;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getWerknemer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>werknemer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> stopManagenVanWerknemer<span style="color: #009900;">&#40;</span>Werknemer werknemer, <span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        WerknemerRelatie relatie <span style="color: #339933;">=</span> bepaalWerknemerRelatie<span style="color: #009900;">&#40;</span>werknemer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>relatie, einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> stopManagen<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemers</span>.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Deze klasse representeert de manager. Als een manager een werknemer gaat managen, wordt de werknemer toegevoegd aan de lijst van te managen werknemers (<code>voegWerknemerToe</code>). Als een werknemer wordt vervangen door een andere werknemer wordt de methode <code>wijzigWerknemer</code> aangeroepen, waardoor de relatie met de oude werknemer wordt beëindigd en de nieuwe werknemer wordt begonnen. Als een werknemer uit dienst gaat of naar een andere afdeling, stopt de manager met het managen van deze werknemer (<code>stopManagenVanWerknemer</code>), waardoor de historische relatie van de manager met de werknemer wordt beëindigd. Als de manager stopt met managen (<code>stopManagen</code>), wordt de relatie met alle gemanagede werknemers beëindigd.</p>
<p>De historische relatie van de manager met de werknemer wordt gerepresenteerd door de klasse <code>WerknemerRelatie</code>.</p>
<p><strong>WerknemerRelatie</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WerknemerRelatie <span style="color: #000000; font-weight: bold;">extends</span> BiTemporalObject <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Werknemer werknemer<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> WerknemerRelatie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> WerknemerRelatie<span style="color: #009900;">&#40;</span>Werknemer werknemer, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemer</span><span style="color: #339933;">=</span> werknemer<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Werknemer getWerknemer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">werknemer</span> <span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>De test ziet er als volgt uit:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	Manager jan <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Manager<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Jan&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// simuleer de opvoer tijd 1-1-2003</span>
	<span style="color: #003399;">Date</span> aanvangsdatum <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2003</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> aanvangsdatum<span style="color: #339933;">;</span> 
&nbsp;
	Afdeling inkoop <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inkoop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jan.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>inkoop, aanvangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Werknemer kees <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Kees&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	kees.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>inkoop, aanvangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jan.<span style="color: #006633;">voegWerknemerToe</span><span style="color: #009900;">&#40;</span>kees, aanvangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Werknemer piet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Piet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	piet.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>inkoop, aanvangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jan.<span style="color: #006633;">voegWerknemerToe</span><span style="color: #009900;">&#40;</span>piet, aanvangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	assertEquals<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertTrue<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>kees<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertTrue<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>piet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003399;">Date</span> wijzigingsdatum <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> wijzigingsdatum<span style="color: #339933;">;</span> 
&nbsp;
	Werknemer johan <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Johan&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	johan.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>inkoop, wijzigingsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Johan vervangt Piet, die uit dienst gaat</span>
	jan.<span style="color: #006633;">wijzigWerknemer</span><span style="color: #009900;">&#40;</span>johan, piet, wijzigingsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	piet.<span style="color: #006633;">uitDienst</span><span style="color: #009900;">&#40;</span>wijzigingsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	assertEquals<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertTrue<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>johan<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertFalse<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>piet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// jan managete gisteren piet nog wel</span>
	<span style="color: #003399;">Date</span> gisteren <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2005</span>, <span style="color: #cc66cc;">12</span>, <span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertTrue<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, gisteren<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>piet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003399;">Date</span> einddatum <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2009</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> wijzigingsdatum<span style="color: #339933;">;</span> 
&nbsp;
	jan.<span style="color: #006633;">stopManagenVanWerknemer</span><span style="color: #009900;">&#40;</span>kees, einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	kees.<span style="color: #006633;">uitDienst</span><span style="color: #009900;">&#40;</span>einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	assertEquals<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertFalse<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>kees<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	jan.<span style="color: #006633;">stopManagen</span><span style="color: #009900;">&#40;</span>einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assertTrue<span style="color: #009900;">&#40;</span>jan.<span style="color: #006633;">getTeManagenWerknemers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In deze test maken we een manager Jan aan, die werkt op de afdeling Inkoop op 1 januari 2003. Vanaf deze dag begint hij ook met het managen van twee werknemers Kees en Piet. Vanaf 1 januari 2006 vervangt een nieuwe werknemer Johan Piet, die uit dienst gaat. Op 1 januari 2009 stopt Jan met het managen van al zijn werknemers.</p>
<h3>Hibernate mappings</h3>
<p>De hibernate mapping van de klasse <code>WerknemerRelatie<code> is analoog aan de mapping van de <code>AfdelingRelatie</code> uit deel 3. </p>
<p>De mapping van de werknemer is uitgebreid met de subclass Manager, die de werknemers als BiTemporalCollection property mapt. </p>
<p><strong>Werknemer.hbm.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping</span> <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;nl.ordina.bitemporal.example&quot;</span> <span style="color: #000066;">default-access</span>=<span style="color: #ff0000;">&quot;field&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Werknemer&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;Werknemer&quot;</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">&quot;Werknemer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;discriminator</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;type&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;versie&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- properties --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;naam&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;naam&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- de verwijzing naar de afdelingrelatie --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;afdelingRelatie&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.ordina.temporal.bitemporal.BiTemporalProperty&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bag</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;alleHistorischeVersies&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;all, delete-orphan&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;werknemerId&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-to-many</span></span>
<span style="color: #009900;">					<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bag<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;subclass</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Manager&quot;</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- de verwijzing naar de werknemerrelatie --&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;werknemers&quot;</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.ordina.temporal.bitemporal.BiTemporalCollection&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bag</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;alleHistorischeVersies&quot;</span></span>
<span style="color: #009900;">					<span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;all, delete-orphan&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;managerId&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-to-many</span></span>
<span style="color: #009900;">						<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;WerknemerRelatie&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bag<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/subclass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>LET OP</strong>: In bovenstaand artikel wordt gesproken over <code>BiTemporalCollection</code>. Dit is niet dezelfde als de <a href="http://martinfowler.com/ap2/temporalProperty.html">BiTemporalCollection van Fowler</a> , wat eigenlijk de <code>BiTemporalProperty</code> uit deel 3 is.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2009/12/07/temporale-data-%e2%80%93-deel-4-bitemporale-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton Smells</title>
		<link>http://blog.smart-java.nl/blog/index.php/2009/04/19/singleton-smells/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2009/04/19/singleton-smells/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 15:05:53 +0000</pubDate>
		<dc:creator>Jan-Kees van Andel</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=370</guid>
		<description><![CDATA[I really hate the Singleton pattern. It makes code hard to test, it has nothing to do with general OO principles and the Singletons I see daily (written by others of course   ) usually look very procedural.
People who use Singletons in Java all the time have more fundamental problems (I&#8217;m not talking about [...]]]></description>
			<content:encoded><![CDATA[<p>I really hate the Singleton pattern. It makes code hard to test, it has nothing to do with general OO principles and the Singletons I see daily (written by others of course <img src='http://blog.smart-java.nl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) usually look very procedural.</p>
<p>People who use Singletons in Java all the time have more fundamental problems (I&#8217;m not talking about singleton scope in Spring btw), so I&#8217;m not gonna rant about that problem here, but I do like to show you an alternative which makes it easier to unit test Singletons.</p>
<p>Neal Ford published <a href="http://www.infoq.com/presentations/10-Ways-to-Better-Code-Neal-Ford">a talk on InfoQ</a> called: <i>&#8220;10 Ways to Improve Your Code&#8221;</i>. Item 4: <i>&#8220;Good citizenship&#8221;</i> is about static methods and especially the Singleton design pattern. Static methods have their usage, for example simple stateless utilities like: <a href="http://java.sun.com/javase/6/docs/api/java/lang/Math.html#sqrt(double)">int Math.sqrt(double)</a> or Apache Commons. But when you&#8217;re going to add state into the mix, things get messy. </p>
<h3>Singleton usage</h3>
<p>Let&#8217;s step back. Why are we using Singletons in the first place?</p>
<ol>
<li>First, as the name says, because you want to guarantee that there is only one instance. Typical examples in the Java libraries are <a href="http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html">java.awt.Toolkit</a> and <a href="http://java.sun.com/javase/6/docs/api/java/io/Console.html">java.io.Console</a>.<br />For those of you interested, Console doesn&#8217;t have a static getConsole method, but can be accessed through <a href="http://java.sun.com/javase/6/docs/api/java/lang/System.html#console()">System.console()</a> and &#8211; in the Sun implementation &#8211; SharedSecrets.getJavaIOAccess().console(). In these cases, a Singleton is needed because there may NEVER be two instances of these classes. Otherwise strange things will happen, because you never know which instance contains the state you need.</li>
<li>Second, and depending on the circumstances this is a good or a bad thing, Singletons are the Object Oriented equivalent of globals. Almost everybody agrees that (non-immutable) globals are very bad, but for some reason, many developers still use Singletons. But, for certain objects, it&#8217;s useful to be able to access them from everywhere, without needing parameters all the time.</li>
</ol>
<p>And of course, there are plenty of myths regarding Singletons, for example because singletons can be lazily instantiated on first use. Well, guess what? Classes are lazily initialized by the ClassLoader, so unless you&#8217;re messing with cyclic initialization dependencies you don&#8217;t need any custom lazy loading mechanism.<br />
By the way, lazy initialization is a bad thing that should be avoided if possible. See <a href="http://java.sun.com/docs/books/effective/">Joshua Bloch&#8217;s Effective Java</a> for more details.</p>
<h3>An example Singleton</h3>
<p>Below is a snippet with an example Singleton. You probably see Singletons like this all day.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> BadSingleton <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> prop1<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> prop2<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> BadSingleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">prop1</span> = <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">prop2</span> = <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> BadSingleton INSTANCE = <span style="color: #000000; font-weight: bold;">new</span> BadSingleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> BadSingleton getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> INSTANCE<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Other methods</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It&#8217;s just a simple Singleton. It uses field initialization for thread safety and simplicity, but is still lazily initialized (by the ClassLoader). Further, initialization is done in the constructor where the environment is queried for some settings.</p>
<p>As you might know, this code is not testable, not even with <a href="http://java.sun.com/javase/6/docs/api/java/lang/reflect/AccessibleObject.html#setAccessible(boolean)">reflection/setAccessible(true)</a> hacking, since the field is declared static + final. See the following snippet for a misguided attempt to create a unit test:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BadSingletonTest <span style="color: #009900;">&#123;</span>
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> testGetInstance_Fail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
        Constructor<span style="color: #339933;">&lt;</span>BadSingleton<span style="color: #339933;">&gt;</span> constructor = BadSingleton.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getDeclaredConstructor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        constructor.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        BadSingleton obj1 = constructor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399; font-weight: bold;">Field</span> field = BadSingleton.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getDeclaredField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSTANCE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        field.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">null</span>, obj1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Exception because INSTANCE is static + final</span>
        BadSingleton obj1 = BadSingleton.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        BadSingleton obj2 = BadSingleton.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Assert.<span style="color: #006633;">assertSame</span><span style="color: #009900;">&#40;</span>obj1, obj2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>An alternative for this issue would be lazy initialization, but this has the disadvantages of not being thread safe when not synchronized correctly. <a href="http://www.javaconcurrencyinpractice.com/">Java Concurrency in Practice</a> by Brian Goetz is a must-read when you are interested in thread safety issues.</p>
<h3>Alternative using a factory</h3>
<p>This is the alternative Singleton class. It&#8217;s a modified version of Neal&#8217;s example.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> GoodSingleton <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> prop1<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> prop2<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> GoodSingleton<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> prop1, <span style="color: #003399; font-weight: bold;">String</span> prop2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">prop1</span> = prop1<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">prop2</span> = prop2<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Other methods</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The responsibility of instantiating the Singleton is programmed into the Factory, which is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GoodSingletonFactory <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> GoodSingleton INSTANCE<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399; font-weight: bold;">String</span> prop1 = <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399; font-weight: bold;">String</span> prop2 = <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Constructor<span style="color: #339933;">&lt;</span>GoodSingleton<span style="color: #339933;">&gt;</span> constructor = GoodSingleton.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getDeclaredConstructor</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #003399; font-weight: bold;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            constructor.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            INSTANCE = constructor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>prop1, prop2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">RuntimeException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error initializing &quot;</span> + GoodSingletonFactory.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> GoodSingleton getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> INSTANCE<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As shown in the snippet, the factory uses reflection to access the private constructor. Note that this trick only works if there is no SecurityManager or if the active SecurityManager approves this action.</p>
<p>It&#8217;s also a little bit less &#8220;Singleton&#8221; since it is possible to have more than one instance. The same reflection trick we used, now works a bit against us. If this is not an issue for you, it doesn&#8217;t matter. After all, developers who want to abuse your API always succeed if they really want to.</p>
<p>But we do get the advantage of better testability, as shown in the following two snippets:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GoodSingletonTest <span style="color: #009900;">&#123;</span>
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> testConstructor_Ok<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
        Constructor<span style="color: #339933;">&lt;</span>GoodSingleton<span style="color: #339933;">&gt;</span> constructor = GoodSingleton.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getDeclaredConstructor</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #003399; font-weight: bold;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        constructor.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        GoodSingleton obj1 = constructor.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Assert stuff</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GoodSingletonFactoryTest <span style="color: #009900;">&#123;</span>
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> testGetInstance_Only_one_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop1&quot;</span>, <span style="color: #0000ff;">&quot;test value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prop2&quot;</span>, <span style="color: #0000ff;">&quot;test value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        GoodSingleton instance1 = GoodSingletonFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Assert.<span style="color: #006633;">assertNotNull</span><span style="color: #009900;">&#40;</span>instance1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        GoodSingleton instance2 = GoodSingletonFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Assert.<span style="color: #006633;">assertNotNull</span><span style="color: #009900;">&#40;</span>instance2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Assert.<span style="color: #006633;">assertSame</span><span style="color: #009900;">&#40;</span>instance1, instance2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, testing now becomes trivial.</p>
<h3>Notes</h3>
<p>Choosing the factory approach has some effects that may be important to you. Here&#8217;s a list of consequences and random thoughts.</p>
<ul>
<li>When using the reflection approach, it is possible for developers to mess up the Singleton behavior using reflection. When they do this, you may end up with multiple instances, which may be undesirable. When using a Singleton and the instance field is declared as static + final, this is not possible. The importance of this point differs per situation.</li>
<li>You can choose to make the constructor package private (default) accessible. This way, you don&#8217;t need reflection to access it from the same package. If you put the Factory and the unit tests in the same package, this will make the code much more readable, especially for less experienced developers. It&#8217;s also less error prone, because the compiler isn&#8217;t capable of doing thorough checks on reflective code. On the other hand, if a developer put&#8217;s a custom class in the same package, it&#8217;s possible to invoke the constructor and thus create multiple instances.</li>
<li>There is a myth that reflection is slow. It&#8217;s true that reflection is not as fast as JIT optimized (plain Java) bytecode. But since about 2000, there have been massive improvements in reflective invocation performance. And of course, if you look at the snippets, reflection is only used the first time.</li>
<li>Using a static initializer block in the Factory and an immutable (all fields final, no lazy initialization) Singleton class makes the entire structure less sensitive to Concurrency hazards. Again, see Brian Goetz&#8217; book for details.</li>
</ul>
<p>If you ask me, the advantages outweigh the disadvantages by miles, especially when you consider that when developers misbehave (like in the first two bullets) in such a way that they break the Singleton principle, they should (and on my projects will) be ass whooped. <img src='http://blog.smart-java.nl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2009/04/19/singleton-smells/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Cyclische dependencies @ runtime</title>
		<link>http://blog.smart-java.nl/blog/index.php/2009/04/16/cyclische-dependencies-runtime/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2009/04/16/cyclische-dependencies-runtime/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 11:01:40 +0000</pubDate>
		<dc:creator>Frank Verbruggen</dc:creator>
				<category><![CDATA[Architectuur]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=353</guid>
		<description><![CDATA[In een gelaagd project zijn er meestal aparte lagen gedefinieerd voor services, domein logica en data access. Stel nu dat er een noodzaak is om vanuit een lager gelegen laag gebruik te maken van functionaliteit die thuis hoort in een hoger gelegen laag. Bijvoorbeeld omdat er in de domein objecten een noodzaak is om gebruik [...]]]></description>
			<content:encoded><![CDATA[<p>In een gelaagd project zijn er meestal aparte lagen gedefinieerd voor services, domein logica en data access. Stel nu dat er een noodzaak is om vanuit een lager gelegen laag gebruik te maken van functionaliteit die thuis hoort in een hoger gelegen laag. Bijvoorbeeld omdat er in de domein objecten een noodzaak is om gebruik te maken van een service. Hoe zorg je er dan voor dat je nette object georienteerde code houdt, zonder dat je compile time dependencies krijgt tussen je projecten / lagen? Het hier gepresenteerde design pattern is een elegante object georienteerde oplossing voor het bovenstaande probleem.</p>
<p>Gegeven een DomeinObject als object uit de lagere laag, en een ServiceImplementation als object uit de hogere laag. De serviceImplementation heeft een een interface methode &#8217;someMethod()&#8217; uit de ServiceInterface die benodigd is om de methode &#8216;businessMethod()&#8217; uit het DomeinObject te implementeren (zie figuur 1, originele klasse diagram).</p>
<p>N.B. Het design pattern is uitgewerkt met domein objecten en service implementaties, maar dat is slechts een invulling.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<img src="http://blog.smart-java.nl/blog/wp-content/uploads/2009/04/originele-situatie.jpg" alt="" /><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Figuur 1, originele klasse diagram<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Los dit als volgt op. Trek de ServiceInterface uit de hogere laag, en zet deze in de lagere laag. Maak een RequiredInterfaceFactory die een instantie van de ServiceInterface kan bevatten. Initialiseer bij het opstarten van je applicatie vanuit de bovenste laag de RequiredInterfaceFactory met de ServiceImplementation (dit kan bijvoorbeeld goed met de Spring configuratie uit Listing 1, Spring configuratie). En implementeer de businessMethod door de aanroep naar de ServiceImplementation als volgt te abstraheren:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">RequiredInterfaceFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServiceInterface</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">someMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Het klasse diagram ziet er dan uit zoals weergegeven in Figuur 2, klasse diagram.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Listing 1, Spring configuratie<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<img src="http://blog.smart-java.nl/blog/wp-content/uploads/2009/04/design-pattern.jpg" alt="" /><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Figuur 2, klasse diagram<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Voordelen en nadelen</strong></p>
<p>Het gebruik van dit design pattern biedt de volgende voordelen:</p>
<ul>
<li>Compile time dependencies zijn niet nodig</li>
<li>At runtime kunnen interface methoden van bovenliggende klassen toch gebruikt worden</li>
<li>Ieder object kan gebruik maken van de interface, ongeacht in welk package het zit, dus het ophalen van de interface kan in de code altijd op dezelfde manier gebeuren</li>
</ul>
<p>Het gebruik van dit design pattern biedt de volgende nadelen:</p>
<ul>
<li>Je moet de RequiredInterfaceFactory injecteren met de ServiceImplementation voordat de rest van de applicatie aangesproken wordt</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2009/04/16/cyclische-dependencies-runtime/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Boekbespreking: Code Complete, 2nd Edition</title>
		<link>http://blog.smart-java.nl/blog/index.php/2009/01/21/boekbespreking-code-complete-2nd-edition/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2009/01/21/boekbespreking-code-complete-2nd-edition/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 16:06:15 +0000</pubDate>
		<dc:creator>Hedzer Westra</dc:creator>
				<category><![CDATA[Boeken]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Methodologieën]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=282</guid>
		<description><![CDATA[
 
Auteur: Steve McConnell, publicatiejaar: 2004, pagina’s: 906, ISBN-13: 978-0735619678, website: http://www.cc2e.com/, Amazon rating: 5 sterren.
 
Code Complete was me jaren geleden aangeraden als hét boek (‘de bijbel’) om te leren nette code te produceren. Enige tijd geleden (!) is de tweede editie uitgekomen, wat me een goed moment leek om deze eens te bestuderen. Het viel [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2009/01/cc2e.bmp"><img class="alignnone size-medium wp-image-283" title="cc2e" src="http://blog.smart-java.nl/blog/wp-content/uploads/2009/01/cc2e.bmp" alt="" /></a></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"> </p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Auteur:<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Steve McConnell</span>, publicatiejaar: 2004, pagina’s: 906, ISBN-13: 978-0735619678, website: <span style="mso-ansi-language: EN-US;" lang="EN-US"><a href="http://www.cc2e.com/"><span style="mso-ansi-language: NL;" lang="NL">http://www.cc2e.com/</span></a></span>,<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Amazon</span><span lang="EN-AU"> </span>rating: 5 sterren.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Code Complete was me jaren geleden aangeraden als hét boek (‘de bijbel’) om te leren nette code te produceren. Enige tijd geleden (!) is de tweede editie uitgekomen, wat me een goed moment leek om deze eens te bestuderen. Het viel me gelijk op dat deze dikke pil van Microsoft<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Press</span> afkomstig is; auteur<span style="mso-ansi-language: EN-AU;"> <span lang="EN-AU">Steve McConnell</span></span><span lang="EN-AU"> </span>komt uit de (Microsoft) wereld van C-programmeurs, maar beheerst vele andere talen.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Het boek geeft de lezer diverse praktische, aan de praktijk gestaafde, gedetailleerde tips en voorbeelden om op een juiste manier programmacode te maken. De meeste voorbeelden gaan uit van C++, Visual<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Basic</span>, Java en C# (in die volgorde). Daar zit ’m wat mij betreft ook meteen een manco: ikzelf ben niet (meer) geïnteresseerd in allerlei tips om onder anderen netjes met pointers en globale variabelen om te gaan. Dat heeft Java netjes voor me afgeschermd… Wel krijg je een interessant kijkje in de keuken van C/C++, en wat extra respect voor programmeurs daarin, die zelfdiscipline nodig hebben, waar wij de taal Java hebben om dezelfde mate van noodzakelijke restrictie te krijgen.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">De structuur, lay-out en leesbaarheid van het boek is zeer goed: er is op een prettig leesbare manier geschreven, hier en daar humoristisch en nergens flauw. Een uitgebreide inhoudsopgave, lijst van tabellen &amp; figuren, referenties, leeslijst van tijdschriften en boeken, en index ontbreken niet. Elk hoofdstuk begint met een duidelijke inleiding van de inhoud, en eindigt met een checklist, samenvatting van de <span style="mso-ansi-language: EN-AU;" lang="EN-AU">‘key points</span>’ en vele referenties naar extra leesvoer. Dat laatste is erg opvallend:<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Steve</span> heeft ontzettend veel materiaal gebruikt bij het samenstellen van dit boek. In het voorwoord claimt hij dan ook dat zijn boek een samenvatting is van heel veel (zo niet alle) succesvolle ontwikkelingen en ontdekkingen op het gebied van softwareconstructie. Overal in het boek staan in de kantlijn referenties naar de ‘cc2e’ website met meer informatie, betekenisvolle quotes van bekende IT-goeroes en kruisverwijzingen. Naast verwijzingen naar onderzoeksresultaten van academici, veelal met statistische gegevens, put de auteur ook uit zijn eigen rijke ervaringen bij o.a. Microsoft, Boeing en NASA. Veel stukken code worden begeleid door een “coding horror” icoontje, om aan te geven hoe verschrikkelijk het desbetreffende antivoorbeeld is.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Het boek omvat 6 delen, onderverdeeld in 35 hoofdstukken, elk met hun eigen onderwerp. Teveel om allemaal te noemen, maar enkele sappige details &amp; citaten wil ik je niet onthouden:</span></p>
<ul style="margin-top: 0cm;" type="disc">
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><em style="mso-bidi-font-style: normal;">“</em><em style="mso-bidi-font-style: normal;"><span style="mso-ansi-language: EN-GB;" lang="EN-GB">Software Construction is the only activity that is guaranteed to be done</span>”</em>: dit is een stevig argument voor Agile werken – waarin documentatie een ondergeschikte rol krijgt toebedeeld ten gunste van productie van programmacode.</span></span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><em style="mso-bidi-font-style: normal;">“</em><em style="mso-bidi-font-style: normal;"><span style="mso-ansi-language: EN-GB;" lang="EN-GB">Program into, not in, a language</span>”</em>: hiermee wil<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Steve</span> je aanzetten om de mogelijkheden van je taal wijselijk te gebruiken, en niet blind alle mogelijkheden – al dan niet op een verkeerde wijze – toe te passen.</span></span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small; font-family: Times New Roman;">De sectie over complexiteit en het beperkte menselijke begripsvermogen is erg vermakelijk.</span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><em style="mso-bidi-font-style: normal;"><span style="mso-ansi-language: EN-GB;" lang="EN-GB"><span style="font-size: small;"><span style="font-family: Times New Roman;">“Don’t optimise your code, unless a profiler or production problem forces you to.”</span></span></span></em></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small; font-family: Times New Roman;">Als alternatief voor nette UML ontwerpen: neem foto’s van tekeningen op<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> whiteboard</span>, of bewaar flip-overs.</span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small; font-family: Times New Roman;">Itereer je design.</span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small; font-family: Times New Roman;">Gebruik tijdens ontwikkeling asserts of excepties die je programma hard doen crashen, maar zorg dat in de productieversie dezelfde fout netjes (liefst zonder interactie van, en overlast voor, de gebruiker) wordt afgehandeld. Dit wordt ook wel<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> offensive</span> vs.<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> defensive programming</span> genoemd.</span></li>
<li class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: small; font-family: Times New Roman;">Schrijf alles altijd uit in pseudo-code. Persoonlijk doe ik dit zeer zelden – en ik heb uit dit boek ook geen extra stimulans daarvoor gehaald, onder anderen door het detailniveau dat wordt aangeraden.</span><span style="font-size: small; font-family: Times New Roman;"> </span></li>
</ul>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Veel van de onderwerpen die beschreven worden –<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> requirements</span>, design, optimalisatie,<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> naming convention</span>, (unit)<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> testing</span>, Design<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> Patterns</span>, encapsulatie, factorisatie,<span style="mso-ansi-language: EN-AU;" lang="EN-AU"> assert</span> vs. excepties vs. <span style="mso-ansi-language: EN-AU;" lang="EN-AU">unit tests, continuous integration, comments vs. refactoring</span> – waren eerlijk gezegd een samenvatting van wat ik al wist. Nuttig om hier en daar iets nieuws te horen, of om even opgefrist te worden, maar echt iets fundamenteels geleerd: nee.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Wat pijnlijk duidelijk wordt, is dat het boek geschreven is vlak voordat Java5 uitkwam – hier en daar wordt Java verweten enkele mogelijkheden te ontberen, terwijl we die al jaren tot onze beschikking hebben.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Concluderend: het boek maakt wat mij betreft zijn belofte slechts gedeeltelijk waar. Voor C++/C#/VB programmeurs is het vast en zeker erg bruikbaar, maar voor Java is het net iets te oud, en ligt er te weinig focus op problemen in Java. Als je junior of medior bent, of voor een breed scala aan onderwerpen in software constructie met één boek klaar wilt zijn, is het een <span style="text-decoration: underline;">goed</span> boek, maar helaas geen <span style="text-decoration: underline;">uitstekend</span> boek…</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small; font-family: Times New Roman;">Kleurindicatie: <strong style="mso-bidi-font-weight: normal;"><span style="color: #ffcc00;">Amber</span></strong> (2 op schaal van 3)</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"> </p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;; mso-ansi-language: NL; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: NL; mso-bidi-language: AR-SA;">Hierbij nodig ik al mijn collega’s uit om ook boekbesprekingen te publiceren op de J-Tech blog, en tevens informatie te plaatsen op de Wiki (<a href="https://wiki.ordina.nl/confluence/display/GENBIEB/Alle+Boeken">https://wiki.ordina.nl/confluence/display/GENBIEB/Alle+Boeken</a>), zodat iedereen een goede keus kan maken uit de vele boeken waarmee je je vaardigheden en kennis kunt uitbreiden. Ikzelf hoop binnenkort te komen met een bespreking van “Programming in Scala,” het eerste boek over deze nieuwe en spannende programmeertaal.</span></p>
<p><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;; mso-ansi-language: NL; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: NL; mso-bidi-language: AR-SA;">Hedzer Westra</span></p>
<p><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;; mso-ansi-language: NL; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: NL; mso-bidi-language: AR-SA;"><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2009/01/hedzerwestra_93x123.jpg"><img class="alignnone size-medium wp-image-284" title="hedzerwestra_93x123" src="http://blog.smart-java.nl/blog/wp-content/uploads/2009/01/hedzerwestra_93x123.jpg" alt="" width="93" height="123" /></a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2009/01/21/boekbespreking-code-complete-2nd-edition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temporale data – deel 3: het bitemporale pattern</title>
		<link>http://blog.smart-java.nl/blog/index.php/2008/12/22/temporale-data-%e2%80%93-deel-3-het-bitemporale-pattern/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2008/12/22/temporale-data-%e2%80%93-deel-3-het-bitemporale-pattern/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 12:18:04 +0000</pubDate>
		<dc:creator>gnoij</dc:creator>
				<category><![CDATA[Tools/Frameworks]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[bitemporal pattern]]></category>
		<category><![CDATA[temporal data]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=275</guid>
		<description><![CDATA[In dit derde deel van de serie over temporale data breidt ik het temporale pattern uit het tweede deel uit met de registratietijd voor opvoer en afvoer. Hierdoor ontstaat het bitemporale pattern.
BiTemporalObject

public abstract class BiTemporalObject implements Cloneable &#123;
&#160;
    private Date ingangsdatum;
&#160;
    private Date einddatum;
&#160;
    private Date [...]]]></description>
			<content:encoded><![CDATA[<p>In dit derde deel van de serie over temporale data breidt ik het temporale pattern uit het <a href="http://blog.smart-java.nl/blog/index.php/2008/12/07/temporale-data-%E2%80%93-deel-2-het-temporale-pattern/">tweede deel</a> uit met de registratietijd voor opvoer en afvoer. Hierdoor ontstaat het bitemporale pattern.</p>
<p><strong>BiTemporalObject</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BiTemporalObject <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Cloneable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> einddatum<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> opvoerTijdstip<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> afvoerTijdstip<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> BiTemporalObject<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ingangsdatum <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ingangsdatum is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span> <span style="color: #339933;">=</span> ingangsdatum<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isGeldigOp<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #003399;">Date</span> peilDatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> isGeregistreerdOp<span style="color: #009900;">&#40;</span>registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> isGeldigOp<span style="color: #009900;">&#40;</span>peilDatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isGeregistreerdOp<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">!</span>isAfgevoerd<span style="color: #009900;">&#40;</span>registratieTijdstip<span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>registratieTijdstip.<span style="color: #006633;">after</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> registratieTijdstip.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isAfgevoerd<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afvoerTijdstip</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>registratieTijdstip.<span style="color: #006633;">after</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afvoerTijdstip</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> registratieTijdstip.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afvoerTijdstip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isGeldigOp<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> peilDatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> geldig <span style="color: #339933;">=</span> peilDatum.<span style="color: #006633;">after</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> peilDatum.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            geldig <span style="color: #339933;">=</span> geldig <span style="color: #339933;">&amp;&amp;</span> peilDatum.<span style="color: #006633;">before</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> geldig<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> BiTemporalObject kopieer<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> wijzigingsdatum, <span style="color: #003399;">Date</span> registratieTijdstip<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// maak een kopie met gevulde einddatum</span>
        BiTemporalObject versie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">kopieer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        versie.<span style="color: #006633;">opvoerTijdstip</span> <span style="color: #339933;">=</span> registratieTijdstip<span style="color: #339933;">;</span>
        versie.<span style="color: #006633;">afvoerTijdstip</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        versie.<span style="color: #006633;">einddatum</span> <span style="color: #339933;">=</span> wijzigingsdatum<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// voer de oude versie af</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afvoerTijdstip</span> <span style="color: #339933;">=</span> registratieTijdstip<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> versie<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getIngangsdatum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getEinddatum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getOpvoerTijdstip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getAfvoerTijdstip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afvoerTijdstip</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>In deze klasse vallen (ten opzichte van <code>TemporalObject</code>) een aantal dingen op. Allereerst dat deze klasse <code>clonable</code> is, verder dat een object pas geldig is als de registratietijd binnen de opvoer en afvoer registratie is en dat er een <code>kopieer</code> methode is, die een kopie (clone) van het object maakt met de huidige opvoertijd en einddatum. Het oorspronkelijke object wordt dan afgevoerd door het vullen van de afvoer registratietijd. Bij creatie van een <code>BiTemporalObject </code>wordt automatisch het opvoertijdstip gevuld met de systeemdatum.</p>
<p><strong>BiTemporalProperty</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BiTemporalProperty <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">List</span> alleHistorischeVersies <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> BiTemporalProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> BiTemporalObject getActueleVersie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> BiTemporalObject getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> peilDatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peilDatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setActueleVersie<span style="color: #009900;">&#40;</span>BiTemporalObject actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>actueleVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;actueleVersie is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        beeindigVorigeVersie<span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> beeindigVorigeVersie<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> BiTemporalObject actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        BiTemporalObject afTeVoerenVersie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                BiTemporalObject versie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BiTemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span> versie.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>actueleVersie.<span style="color: #006633;">getOpvoerTijdstip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, actueleVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>afTeVoerenVersie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            BiTemporalObject kopieVersie <span style="color: #339933;">=</span> afTeVoerenVersie.<span style="color: #006633;">kopieer</span><span style="color: #009900;">&#40;</span>actueleVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, actueleVersie.<span style="color: #006633;">getOpvoerTijdstip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>kopieVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beeindig<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        BiTemporalObject teBeeindigenVersie <span style="color: #339933;">=</span> getActueleVersie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>teBeeindigenVersie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            BiTemporalObject kopieVersie <span style="color: #339933;">=</span> teBeeindigenVersie.<span style="color: #006633;">kopieer</span><span style="color: #009900;">&#40;</span>einddatum, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>kopieVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>Het verschil van de <code>BiTemporalProperty</code> met de <code>TemporalProperty</code> is dat er nu twee tijdstippen worden meegegeven om de juiste versie te bepalen. Naast de peildatum is dat ook het registratietijdstip. Als er een actuele versie wordt toegevoegd of beëindigd, wordt de op dat moment geldende versie gekopieerd en afgevoerd. De gekopieerde versie wordt beëindigd. Hierdoor zal er altijd bij beëindiging of wijziging een extra record ontstaan. Dit wordt verklaard in de concepten voor bitemporale data in <a href="http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%E2%80%93-deel-1-de-concepten/">deel 1</a>.</p>
<h3>Een voorbeeld</h3>
<p>We gebruiken hier hetzelfde voorbeeld als uit deel 2. </p>
<p><strong>Werknemer</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Werknemer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> BiTemporalProperty afdelingRelatie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BiTemporalProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> naam<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> naam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span> <span style="color: #339933;">=</span> naam<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNaam<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAfdeling<span style="color: #009900;">&#40;</span>Afdeling afdeling, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">setActueleVersie</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AfdelingRelatie<span style="color: #009900;">&#40;</span>afdeling, ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        AfdelingRelatie relatie <span style="color: #339933;">=</span> getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>relatie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> relatie.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        AfdelingRelatie relatie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getVersieOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>relatie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> relatie.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AfdelingRelatie getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getActueleVersie</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AfdelingRelatie getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> registratieTijdstip, <span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getVersieOp</span><span style="color: #009900;">&#40;</span>registratieTijdstip, peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> uitDienst<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> datumUitdienst<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>datumUitdienst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>Ten opzichte van de klasse <code>Werknemer</code> uit deel 2 hebben de methoden <code>getAfdeling</code> en <code>getAfdelingRelatie</code> een extra parameter <code>registratieTijdstip</code>. </p>
<p><strong>AfdelingRelatie</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AfdelingRelatie <span style="color: #000000; font-weight: bold;">extends</span> BiTemporalObject <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Afdeling afdeling<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> AfdelingRelatie<span style="color: #009900;">&#40;</span>Afdeling afdeling, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdeling</span> <span style="color: #339933;">=</span> afdeling<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdeling</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Deze klasse <code>AfdelingRelatie</code> is afgeleid van de klasse <code>BiTemporalObject</code>. Verder is deze analoog aan de klasse uit deel 2. </p>
<p>De klasse Afdeling is analoog aan de klasse Afdeling uit deel 2.</p>
<p> De test ziet er als volgt uit:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testWerknemer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Werknemer werknemer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Kees&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// simuleer de opvoer tijd 1-1-2003</span>
        BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2003</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Afdeling inkoop <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inkoop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        werknemer.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>inkoop, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2003</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// simuleer de opvoer tijd 1-2-2006</span>
        BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Afdeling verkoop <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        werknemer.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>verkoop, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Kees&quot;</span>, werknemer.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">vandaag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span>, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// simuleer de opvoer tijd 1-2-2008</span>
        BiTemporalObject.<span style="color: #006633;">TEST_OPVOER_TIJDSTIP</span> <span style="color: #339933;">=</span> DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2008</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        werknemer.<span style="color: #006633;">uitDienst</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2008</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertNull<span style="color: #009900;">&#40;</span>werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>In deze test maken we een werknemer Kees aan, die begint te werken op de afdeling Inkoop op 1 januari 2003. Dit wordt op dezelfde datum geregistreerd. Vanaf 1 januari 2006 werkt Kees op de afdeling Verkoop, wat pas op 1 februari wordt geregistreerd en vanaf  1 januari 2008 is Kees uit dienst. Dit wordt een maand later pas geregistreerd.</p>
<p>Omdat de registratietijd automatisch wordt bepaald heb ik (uitsluitend voor testdoeleinden) de klasse BiTemporalObject uitgebreid met een public static member <code>TEST_OPVOER_TIJDSTIP</code>, om de registratietijd uit het voorbeeld te kunnen simuleren. Hierdoor verandert de constructor van <code>BiTemporalObject</code> in</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">protected</span> BiTemporalObject<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ingangsdatum <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ingangsdatum is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span> <span style="color: #339933;">=</span> ingangsdatum<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// voor testdoeleinden</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>TEST_OPVOER_TIJDSTIP <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">opvoerTijdstip</span> <span style="color: #339933;">=</span> TEST_OPVOER_TIJDSTIP<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<h3>Hibernate mappings</h3>
<p>De hibernate mapping van de klasse <code>Werknemer</code> en <code>Afdeling</code> zijn analoog aan die van de klasse <code>Werknemer</code> uit deel 2.<br />
De mapping van de klasse <code>AfdelingRelatie</code> is uitgebreid met de opvoer- en afvoer registratietijd. </p>
<p><strong>AfdelingRelatie</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping</span> <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;nl.ordina.bitemporal.example&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">default-access</span>=<span style="color: #ff0000;">&quot;field&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;versie&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- temporale informatie --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ingangsdatum&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;einddatum&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;opvoerTijdstip&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;afvoerTijdstip&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- de verwijzing naar de afdeling --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;many-to-one</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;afdeling&quot;</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;Afdeling&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;afdelingId&quot;</span> <span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;none&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Het volgende deel zal het bitemporale pattern uitbreiden met historische collections.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2008/12/22/temporale-data-%e2%80%93-deel-3-het-bitemporale-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temporale data – deel 2: het temporale pattern</title>
		<link>http://blog.smart-java.nl/blog/index.php/2008/12/07/temporale-data-%e2%80%93-deel-2-het-temporale-pattern/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2008/12/07/temporale-data-%e2%80%93-deel-2-het-temporale-pattern/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 11:32:49 +0000</pubDate>
		<dc:creator>gnoij</dc:creator>
				<category><![CDATA[Tools/Frameworks]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[historie]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[temporal pattern]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=267</guid>
		<description><![CDATA[Zoals al in het eerste deel te zien was is temporale data op te delen in temporale (alleen geldigheid) of bitemporale data (geldigheid met registratietijd). In dit tweede deel beschrijf ik het pattern voor temporale data.
De kern van dit pattern zijn de Java klassen TemporalObject en TemporalProperty. TemporalObject bevat de logica voor de geldigheid en [...]]]></description>
			<content:encoded><![CDATA[<p>Zoals al in het <a href="http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%E2%80%93-deel-1-de-concepten/">eerste deel</a> te zien was is temporale data op te delen in temporale (alleen geldigheid) of bitemporale data (geldigheid met registratietijd). In dit tweede deel beschrijf ik het pattern voor temporale data.</p>
<p>De kern van dit pattern zijn de Java klassen <tt>TemporalObject</tt> en <tt>TemporalProperty</tt>. <tt>TemporalObject</tt> bevat de logica voor de geldigheid en <tt>TemporalProperty</tt> bevat de code om een de juiste versie van een property te kunnen bepalen.</p>
<p>
<b>TemporalObject</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> TemporalObject <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> einddatum<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> TemporalObject<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ingangsdatum <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ingangsdatum is verplicht&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span> <span style="color: #339933;">=</span> ingangsdatum<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isGeldigOp<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> geldig <span style="color: #339933;">=</span> peildatum.<span style="color: #006633;">after</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> peildatum.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            geldig <span style="color: #339933;">=</span> geldig <span style="color: #339933;">&amp;&amp;</span> peildatum.<span style="color: #006633;">before</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> geldig<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getIngangsdatum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ingangsdatum</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> getEinddatum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beeindig<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">einddatum</span> <span style="color: #339933;">=</span> einddatum<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>Deze klasse is de superklasse van een klasse met geldigheid. Deze klasse bevat de ingangsdatum en einddatum van een versie. Deze klasse bevat alleen een constructor met ingangsdatum, omdat deze verplicht is (anders kunnen we geen historie bijhouden). Verder kent deze klasse de methode om de te vragen of een object geldig is op een bepaalde datum en een methode om een instantie te kunnen beëindigen. Deze klasse is gebaseerd op het <a href="http://www.martinfowler.com/eaaDev/Effectivity.html">Effectivity Pattern</a> van Martin Fowler. </p>
<p>
<b>TemporalProperty</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TemporalProperty <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">List</span> alleHistorischeVersies <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> TemporalProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> TemporalObject getActueleVersie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> TemporalObject getVersieOp<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>TemporalObject<span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setActueleVersie<span style="color: #009900;">&#40;</span>TemporalObject actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>actueleVersie <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;actueleVersie is null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        beeindigVorigeVersie<span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>actueleVersie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> beeindigVorigeVersie<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> TemporalObject actueleVersie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        TemporalObject teBeeindigenVersie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TemporalObject<span style="color: #009900;">&#41;</span> CollectionUtils.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">alleHistorischeVersies</span>, <span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                TemporalObject versie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TemporalObject<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span> versie.<span style="color: #006633;">isGeldigOp</span><span style="color: #009900;">&#40;</span>actueleVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>teBeeindigenVersie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            teBeeindigenVersie.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>actueleVersie.<span style="color: #006633;">getIngangsdatum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beeindig<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> einddatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        TemporalObject teBeeindigenVersie <span style="color: #339933;">=</span> getActueleVersie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>teBeeindigenVersie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            teBeeindigenVersie.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>einddatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>Deze klasse wordt gebruikt om alle historische versies van een property bij te houden. Deze klasse kent methoden om de actuele versie op te vragen, om de versie die op een bepaalde datum geldig is op te vragen en om een nieuwe actuele versie toe te voegen of te beëindigen. Als er een nieuwe actuele versie wordt toegevoegd, wordt de op dat moment geldende versie beëindigd. Deze klasse is gebaseerd op de <a href="http://www.martinfowler.com/eaaDev/TemporalProperty.html">TemporalProperty Pattern</a> van Martin Fowler. </p>
<p><i><b>Let op:</b> Fowler noemt deze klasse <tt>TemporalCollection</tt>. Deze naam gebruik ik voor de lijst properties met historie, die ik in deel 4 zal behandelen. </i></p>
<h3>Voorbeeld</h3>
<p>Om de werking van bovenstaande klassen uit te leggen gebruiken we het voorbeeld uit deel 1. </p>
<p><i>Kees werkte vanaf 1-1-2003 op de afdeling Inkoop. Vanaf 1-1-2006 werkt hij op de afdeling Verkoop. Deze overgang werd op 1-2-2006 geregistreerd in het systeem.</i></p>
<p>We hebben hier te maken met de klassen <tt>Werknemer</tt> en <tt>Afdeling</tt>. Omdat de afdeling bij meerdere werknemers voor kan komen gebruiken we een <tt>AfdelingRelatie</tt> klasse om de geldigheid van een afdeling bij een werknemer te registreren.
<p>Het klasse model ziet er als volgt uit:<br />
<a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/12/classmodel-temporal-afdelingrelatie.png"><img src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/12/classmodel-temporal-afdelingrelatie.png" alt="" title="klasse model werknemer-afdeling" width="500" height="127" class="aligncenter size-full wp-image-269" /></a>
</p>
<p><b>Werknemer</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Werknemer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> TemporalProperty afdelingRelatie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TemporalProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> naam<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> naam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span> <span style="color: #339933;">=</span> naam<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNaam<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAfdeling<span style="color: #009900;">&#40;</span>Afdeling afdeling, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">setActueleVersie</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AfdelingRelatie<span style="color: #009900;">&#40;</span>afdeling, ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        AfdelingRelatie relatie <span style="color: #339933;">=</span> getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>relatie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> relatie.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        AfdelingRelatie relatie <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getVersieOp</span><span style="color: #009900;">&#40;</span>peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>relatie <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> relatie.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AfdelingRelatie getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getActueleVersie</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AfdelingRelatie getAfdelingRelatie<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> peildatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>AfdelingRelatie<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">getVersieOp</span><span style="color: #009900;">&#40;</span>peildatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> uitDienst<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> datumUitdienst<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdelingRelatie</span>.<span style="color: #006633;">beeindig</span><span style="color: #009900;">&#40;</span>datumUitdienst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>De klasse <tt>Werknemer</tt> bevat een temporal property <tt>afdelingRelatie</tt> die alle historische versies van de afdelingen van de werknemer bevat. Verder bevat deze klasse de public methoden om de huidige afdeling op te vragen, de afdeling waar de werknemer werkte op een bepaalde datum op te vragen en om een nieuwe afdeling te koppelen aan de werknemer. Het opvragen en koppelen van de afdeling verloopt via de relatieklasse <tt>AfdelingRelatie</tt>, die de historie van een enkele versie bijhoudt. Als een werknemer uit dienst gaat, wordt de actuele versie van de relatie beëindigd.</p>
<p><b>AfdelingRelatie</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AfdelingRelatie <span style="color: #000000; font-weight: bold;">extends</span> TemporalObject <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Afdeling afdeling<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> AfdelingRelatie<span style="color: #009900;">&#40;</span>Afdeling afdeling, <span style="color: #003399;">Date</span> ingangsdatum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>ingangsdatum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdeling</span> <span style="color: #339933;">=</span> afdeling<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling getAfdeling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">afdeling</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>De klasse <tt>AfdelingRelatie</tt> is afgeleid van de klasse TemporalObject omdat deze klasse de geldigheid bevat van de relatie tussen de werknemer en de afdeling. Omdat een temporal object <i>immutable</i> is, kan er alleen maar een nieuwe versie via de constructor worden aangemaakt met een ingangsdatum die de datum voorstelt waarop de werknemer op de nieuwe afdeling komt te werken.</p>
<p><b>Afdeling</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Afdeling <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> naam<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> naam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span> <span style="color: #339933;">=</span> naam<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNaam<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">naam</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>De klasse <tt>Afdeling</tt> is een eenvoudige klasse die voor ons voorbeeld alleen de naam van de afdeling bevat.
<p>Het gebruik van de klassen en methoden volgt uit de volgende unit test.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testWerknemer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Werknemer werknemer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Werknemer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Kees&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Afdeling afdeling <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inkoop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		werknemer.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>afdeling, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2003</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		afdeling <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Afdeling<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		werknemer.<span style="color: #006633;">setAfdeling</span><span style="color: #009900;">&#40;</span>afdeling, DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Kees&quot;</span>, werknemer.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Verkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2006</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inkoop&quot;</span>, werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2004</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNaam</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		werknemer.<span style="color: #006633;">uitDienst</span><span style="color: #009900;">&#40;</span>DateUtils.<span style="color: #006633;">maakDate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2008</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	assertNull<span style="color: #009900;">&#40;</span>werknemer.<span style="color: #006633;">getAfdeling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><p>In deze test maken we een werknemer Kees aan, die begint te werken op de afdeling Inkoop op 1 januari 2003. Vanaf 1 januari 2006 werkt Kees op de afdeling Verkoop en vanaf  1 januari 2008 is Kees uit dienst.</p>
<h3>Hibernate mappings</h3>
<p>Tenslotte wil ik nog de Hibernate mappings voor de klassen <tt>Werknemer</tt> en <tt>AfdelingRelatie</tt> tonen om te laten zien hoe dit in zijn werk gaat.</p>
<p><b>Werknemer.hbm.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping</span> <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;nl.ordina.temporal.example&quot;</span> <span style="color: #000066;">default-access</span>=<span style="color: #ff0000;">&quot;field&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Werknemer&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;Werknemer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
		... 
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;naam&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;naam&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- de verwijzing naar de afdelingrelatie --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;afdelingRelatie&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.ordina.temporal.singletemporal.TemporalProperty&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bag</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;alleHistorischeVersies&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;all, delete-orphan&quot;</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;werknemerId&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-to-many</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bag<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p>De temporal property <tt>afdelingRelatie</tt> wordt als een component opgenomen in de mapping van <tt>Werknemer</tt>. Hierbinnen wordt de lijst <tt>alleHistorischeRelaties</tt> gemapt als een <tt>bag</tt>.</p>
<p><b>AfdelingRelatie.hbm.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping</span> <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;nl.ordina.temporal.example&quot;</span> 	<span style="color: #000066;">default-access</span>=<span style="color: #ff0000;">&quot;field&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;AfdelingRelatie&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 		...
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- temporale informatie --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ingangsdatum&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;einddatum&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;date&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- de verwijzing naar de afdeling --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;many-to-one</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;afdeling&quot;</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;Afdeling&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;afdelingId&quot;</span> <span style="color: #000066;">cascade</span>=<span style="color: #ff0000;">&quot;none&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p>De mapping van de <tt>AfdelingRelatie</tt> bevat  de properties ingangsdatum en einddatum en een <tt>many-to-one</tt> relatie met de klasse <tt>Afdeling</tt>, die hier verder niet getoond wordt.</p>
<p>In het volgende deel zal het <tt>bitemporale pattern</tt> getoond worden. Hierbij zal het voorbeeld worden uitgebreid met registratiegegevens.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2008/12/07/temporale-data-%e2%80%93-deel-2-het-temporale-pattern/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Temporale data – deel 1: de concepten</title>
		<link>http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%e2%80%93-deel-1-de-concepten/</link>
		<comments>http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%e2%80%93-deel-1-de-concepten/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 20:49:01 +0000</pubDate>
		<dc:creator>gnoij</dc:creator>
				<category><![CDATA[Tools/Frameworks]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[temporal data]]></category>

		<guid isPermaLink="false">http://blog.smart-java.nl/blog/?p=252</guid>
		<description><![CDATA[In een serie van 4 artikelen wil ik een framework voor gebruik van temporale data presenteren. In dit eerste deel wordt uitgelegd wat temporale data is en wat de consequenties zijn. In de volgende delen wordt het framework in een aantal stappen gepresenteerd.
Een korte introductie in temporale data
Temporale data is data waarbij tijdsaspecten een rol [...]]]></description>
			<content:encoded><![CDATA[<p>In een serie van 4 artikelen wil ik een framework voor gebruik van temporale data presenteren. In dit eerste deel wordt uitgelegd wat temporale data is en wat de consequenties zijn. In de volgende delen wordt het framework in een aantal stappen gepresenteerd.</p>
<h3><strong>Een korte introductie in temporale data</strong></h3>
<p>Temporale data is data waarbij tijdsaspecten een rol spelen.</p>
<p>Ter illustratie even een voorbeeld van een simpel HRM systeem:</p>
<p style="padding-left: 30px;"><em>Kees werkte vanaf 1-1-2003 op de afdeling Inkoop. Vanaf 1-1-2006 werkt hij op de afdeling Verkoop. Deze overgang werd op 1-2-2006 geregistreerd in het systeem.</em></p>
<p>Schematisch ziet dat er als volgt uit:</p>
<p><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/hrm-voorbeeld.png"><img class="size-medium wp-image-253 aligncenter" title="HRM voorbeeld" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/hrm-voorbeeld.png" alt="HRM voorbeeld" width="532" height="267" /></a></p>
<p>Uit bovenstaand voorbeeld blijkt dat de tijdsaspecten die een rol kunnen spelen zijn: een ingangsdatum, een einddatum en een registratiedatum. Welke tijdaspecten voor de te ontwikkelen applicatie een rol spelen hangt af van de vragen die de applicatie moet kunnen beantwoorden.</p>
<p>De mogelijke vragen met betrekking tot de tijdsaspecten in bovenstaand voorbeeld zijn:</p>
<ol style="margin-top: 0cm;" type="1">
<li>Waar werkt Kees nu?</li>
<li>Sinds wanneer werkt Kees op de afdeling Verkoop?</li>
<li>Gedurende welke periode werkte Kees op de afdeling Inkoop?</li>
<li>Op welke afdeling werkte Kees op 15-1-2006 als we keken in het systeem op 15-1-2006?</li>
</ol>
<p>Om elke vraag te kunnen beantwoorden heb je andere tijdsaspecten nodig.</p>
<p>Vraag 1 kun je beantwoorden zonder extra tijdsgegevens op te slaan.Vraag 2 kun je beantwoorden door een ingangsdatum te gebruiken.Voor vraag 3 heb je een ingangsdatum en een einddatum nodig en voor vraag 4 heb je naast de ingangs- en einddatum ook registratiedata nodig.</p>
<p>Om de vragen 2, 3 en 4 ook voor het verleden te kunnen beantwoorden moet er ook historie van de data worden bijgehouden. Dat betekent dat elke wijziging leidt tot een nieuw record in de database.</p>
<p>De historievormen met geldigheid (een ingangsdatum en een einddatum) noemen we <em>temporale data</em> en met geldigheid en registratiedata <em>bitemporale data</em>.</p>
<h3><strong>temporale data</strong></h3>
<p>Bij <em>temporale data</em> hebben we te maken met de tijdsaspecten ingangsdatum en einddatum. Willen we ook historie gaan bijhouden, moeten de wijzigingen op een temporal object leiden tot een nieuw record in de database. Dat betekent dat een object in principe <em>immutable</em> is. Wijzigingen op een object leiden altijd tot een nieuw object.</p>
<p>In principe onderscheiden we drie situaties: inschrijving, wijziging en beëindiging van de data.</p>
<p>Bij inschrijving wordt er een record aan een tabel toegevoegd in de database toegevoegd. Voor ons voorbeeld ziet dat er als volgt uit:</p>
<div class="mceTemp mceIEcenter">
<dl id="attachment_255" class="wp-caption aligncenter" style="width: 510px;">
<dt class="wp-caption-dt"><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-insert1.png"><img class="size-full wp-image-255" title="temporal-insert1" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-insert1.png" alt="temporal insert" width="500" height="72" /></a></dt>
</dl>
</div>
<p style="text-align: center;"><em>De FK kolom wijst naar de tabel Werknemer met Primary Key 1.</em></p>
<p>Voor een wijziging wordt er een nieuw record in de tabel geschreven, en wordt het vorige record afgesloten met een einddatum.</p>
<p><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-change.png"><img class="aligncenter size-full wp-image-256" title="temporal-change" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-change.png" alt="" width="500" height="92" /></a></p>
<p>Tenslotte voor een beëindiging wordt het actuele record afgesloten met een einddatum. Als in het voorbeeld Kees uit dienst gaat op 1-1-2008 krijgen we de volgende records te zien.</p>
<p><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-ending.png"><img class="aligncenter size-full wp-image-257" title="temporal-ending" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/temporal-ending.png" alt="" width="500" height="93" /></a></p>
<p>We kunnen nu de vragen 1 tot en met 3 beantwoorden, maar niet vraag 4.</p>
<p>Antwoorden:</p>
<ol>
<li>Nergens, want Kees is per 1-1-2008 uit dienst.</li>
<li>Sinds 1-1-2006 werkte Kees op de afdeling Verkoop</li>
<li>Tussen 1-1-2003 en 1-1-2006 werkte Kees op de afdeling Inkoop</li>
<li>Op 15-1-2006 wisten wij dat Kees op de afdeling Verkoop werkte. <strong>(Terwijl het systeem dit pas op 1-2-2006 heeft geregistreerd, dus is het antwoord fout. Dit moet <em>Inkoop</em> zijn)</strong></li>
</ol>
<h3><strong>bitemporale data</strong></h3>
<p>Zoals uit bovenstaande records blijkt kunnen we niet achterhalen wanneer iets is geregistreerd. Of wanneer de organisatie wist wanneer een wijziging is doorgevoerd. In sommige (vooral juridische) situaties is dit wel nodig. Hiervoor moeten we de geldigheid uitbreiden met registratiedata voor opvoer en afvoer. Dit noemen we <em>bitemporale data</em></p>
<p>We kunnen dezelfde drie situaties als bij temporale data onderscheiden: inschrijving, wijziging en beëindiging.</p>
<p>Bij inschrijving wordt er een record aan de database toegevoegd. Dit is te zien in onderstaande tabel.</p>
<p style="text-align: center;"><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-insert.png"><img class="size-full wp-image-260 aligncenter" title="bitemporal-insert" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-insert.png" alt="" width="542" height="71" /></a></p>
<p style="text-align: center;"><em>Hierbij zijn de kolommen Opvoer en Afvoer toegevoegd aan de tabel.</em></p>
<p>Bij wijziging wordt het eerste record afgesloten, wordt er een kopie gemaakt met einddatum en wordt de wijziging toegevoegd.</p>
<p><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-change.png"><img class="aligncenter size-full wp-image-258" title="bitemporal-change" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-change.png" alt="" width="538" height="105" /></a></p>
<p style="text-align: center;"><em>Per wijziging wordt dus (naast de wijziging) een extra record in de database toegevoegd met de oorspronkelijke informatie plus een afvoerdatum.</em></p>
<p>Bij beëindiging wordt een kopie gemaakt van het actuele record, de actuele versie krijgt een afvoerdatum en de kopie krijgt een einddatum.</p>
<p><a href="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-ending.png"><img class="aligncenter size-full wp-image-259" title="bitemporal-ending" src="http://blog.smart-java.nl/blog/wp-content/uploads/2008/11/bitemporal-ending.png" alt="" width="538" height="125" /></a></p>
<p style="text-align: center;"><em>Ook voor beëindiging wordt een extra record toegevoegd met de oorspronkelijke informatie plus een afvoerdatum.</em></p>
<p>Met het gebruik van zowel geldigheid als registratiedata is ook vraag 4 juiste te beantwoorden. Door te zoeken naar het record dat opgevoerd is voor 15-1-2006 en niet voor die datum is afgevoerd zien we dat het juiste antwoord <em>Inkoop</em> is.</p>
<h3>Mogelijke oplossingen</h3>
<p>Mogelijke oplossingsrichtingen voor de bouw van applicaties met (bi)temporale data zijn:</p>
<ul>
<li>Temporale databases en SQL/Temporal (o.a. <a title="Oracle Flashback" href="http://www.oracle.com/technology/deploy/availability/htdocs/Flashback_Overview.htm" target="_blank">Oracle Flashback</a> en <a title="TimeDb" href="http://www.timeconsult.com/" target="_blank">TimeDB</a>)</li>
<li>Gebruik van SQL code (zie o.a. <a title="Developing time-oriented database applications in SQL" href="http://www.cs.arizona.edu/people/rts/tdbbook.pdf" target="_blank">http://www.cs.arizona.edu/people/rts/tdbbook.pdf</a>)</li>
<li>Maatwerk oplossing in (Java) code (o.a. via de <a title="Temporal Patterns" href="http://www.martinfowler.com/eaaDev/index.html" target="_blank">Temporal patterns</a> van Martin Fowler)</li>
</ul>
<p>
Het framework dat ik in de volgende artikelen wil presenteren is gebaseerd op de maatwerkoplossing, waarbij gebruik wordt gemaakt van de Temporal patterns van Fowler.</p>
<p>Dit framework bestaat uit patterns voor temporale data en bitemporale data. In het volgende artikel zal ik patterns voor temporale data<span> </span>presenteren. Het derde deel zal patterns voor bitemporale data behandelen en in het (voorlopig) laatste deel zullen we deze patterns uitbreiden voor collections.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smart-java.nl/blog/index.php/2008/11/19/temporale-data-%e2%80%93-deel-1-de-concepten/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
