<?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>Platformability &#187; Caplin Trader</title>
	<atom:link href="http://blog.caplin.com/tag/caplin-trader/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caplin.com</link>
	<description>Single Dealer Platforms, Industry Expertise</description>
	<lastBuildDate>Fri, 03 Feb 2012 15:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fun with Text Encodings</title>
		<link>http://blog.caplin.com/2011/02/10/fun-with-text-encodings/</link>
		<comments>http://blog.caplin.com/2011/02/10/fun-with-text-encodings/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 13:18:29 +0000</pubDate>
		<dc:creator>Ian Gilham</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Caplin Trader]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalisation]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=5076</guid>
		<description><![CDATA[Now that we are building robust internationalisation support into Caplin Trader, there are numerous testing scenarios that can put pressure on the computer running the tests. To avoid corruption, we need proper operating system support, editor support, and to thoroughly test every system that can access the locale files (eg....]]></description>
			<content:encoded><![CDATA[<p>Now that we are building robust internationalisation support into Caplin Trader, there are numerous testing scenarios that can put pressure on the computer running the tests. To avoid corruption, we need proper operating system support, editor support, and to thoroughly test every system that can access the locale files (eg. version control).</p>
<p>So how can we get around the encoding issues and end up with testable locale files?</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvdW5lc2NhcGUtdW5pY29kZTEucG5n"><img class="aligncenter size-full wp-image-5102" src="http://blog.caplin.com/wp-content/uploads/unescape-unicode1.png" alt="From English to Unicode escaped Chinese to legible Chinese" width="600" height="300" /></a></p>
<p><span id="more-5076"></span></p>
<p>We have quite a broad base of different operating systems in use at Caplin, most of which are fine. Even Windows XP works well enough after installing some of the optional language support.</p>
<p>Then there are the editors. In addition to various text editors, Eclipse is the IDE of choice at Caplin, and it has a well hidden setting to override the default file encoding (Preferences -&gt; General -&gt; Workspace -&gt; Text file encoding) and work with UTF-8 everywhere. This can also be done on a per-project basis if necessary.</p>
<p>That should be enough to get started. We already had a default locale file, so I used <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5vbWVnYXQub3JnLw==" 0="target="_blank"">OmegaT</a> to machine translate it into bad Chinese and saved the result. Unfortunately, the new file is full of unicode escape sequences &#8211; strings in the form <strong>&#8220;\uXXXX\uYYYY\uZZZZ&#8221;</strong>. That can be used but is no good for testing, so I went in search of a simple tool to unescape the text in the file and output the result in UTF-8.</p>
<p>It was surprisingly hard to find a suitable tool online. So much so that I ended up writing my own. First I tried Java because it should work everywhere and has extensive unicode support. After fighting with it for a little while, and only getting encoding problems in the output and no error messages at all, I decided to use something else.</p>
<p>I wrote a quick script in Python to do the conversion and spent some time analysing the errors that occurred when trying to write the output to the console.</p>
<p>After some hair-pulling, I realised that it was trying to output text in the encoding of the calling process, a DOS window (cp850). The DOS, or more properly cmd environment simply doesn&#8217;t support asian scripts. It barely even supports English, come to that.</p>
<p>Thankfully, the solution was quite simple. All I had to do was open a file with the desired encoding and write directly to that. The resulting <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9naXRodWIuY29tL2lnaWxoYW0vcHl0ZXh0dXRpbHMvYmxvYi9tYXN0ZXIvc3JjL3VuZXNjYXBlLnB5" 0="target="_blank"">python script to unescape unicode strings</a> is on GitHub.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=5076" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2011/02/10/fun-with-text-encodings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 Toolkits for Complex Web Applications</title>
		<link>http://blog.caplin.com/2010/12/01/html5-toolkits-for-complex-web-applications/</link>
		<comments>http://blog.caplin.com/2010/12/01/html5-toolkits-for-complex-web-applications/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 14:52:48 +0000</pubDate>
		<dc:creator>Andrew MacLeod</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[UX]]></category>
		<category><![CDATA[Caplin Trader]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=4417</guid>
		<description><![CDATA[Embarking on developing a web application can be bewildering: there's no shortage of JavaScript toolkits of all different shapes and sizes but there's no guiding light.  This article attempts to navigate through the maze of toolkits to assist making technology choices when building a web application.]]></description>
			<content:encoded><![CDATA[<p>At Caplin, we build very complex web applications for financial trading, and we are often asked for advice about which of the many JavaScript toolkits out there are the best.</p>
<p>Embarking on developing a web application can be bewildering: there&#8217;s no shortage of JavaScript toolkits of all different shapes and sizes but there&#8217;s no guiding light.  Microsoft and Adobe, by contrast, offer a much greater degree of comfort with their methodologies, libraries and tool support &#8211; but only if you are willing to restrict your application to running on their respective platforms.</p>
<p>There are some great JavaScript tools out there, however, and this article attempts to navigate through the maze of toolkits to assist making technology choices when building a web application.</p>
<p><strong>User Experience is Paramount</strong></p>
<p>The GUI is the most prominent part of the application, and is usually the most expensive to develop.  An important part of the UX rests on your choice of widgets and how customisable they are.  You should choose widgets that will give you the best possible starting point; if you can&#8217;t find what you want, you will have to consider composing your own.</p>
<p><span id="more-4417"></span></p>
<p>Most widget toolkits are general purpose, but more sophisticated widgets are emerging.  <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Rldi5leHRqcy5jb20vZGVwbG95L2Rldi9leGFtcGxlcy8=">ExtJS</a>, <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pxdWVyeXVpLmNvbS9kZW1vcy8=">jQuery</a> and <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbW9zLmRvam90b29sa2l0Lm9yZy9kZW1vcy8=">Dojo</a> provide widgets ranging from grids to email suites.  Caplin specifically targets widgets for financial sector clients that are oriented to financial domain specific objects and delivering real-time prices to the screen.</p>
<p>Widgets are typically customised using templates, configuration and programatically.  Templating is by far the quickest approach, and this has been well proven with Silverlight’s XAML.  HTML also works very well as a view templating language, and HTML5’s data attributes can be used to further this approach.  Caplin has developed some easy-to-use frameworks that use HTML/CSS templating to build new widgets quickly.</p>
<p>UX does not stop at widget selection though: how they interact is also crucial.  User workflow across all the widgets in the application needs to be implemented with due respect to the overall application structure.</p>
<p><strong>Structural Patterns</strong></p>
<p>Most GUIs conform to some kind of structural pattern.   <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21hcnRpbmZvd2xlci5jb20vZWFhRGV2L1Bhc3NpdmVTY3JlZW4uaHRtbA==">Passive View</a>, <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9QcmVzZW50ZXJfRmlyc3Q=">Presenter First</a> and <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21hcnRpbmZvd2xlci5jb20vZWFhRGV2L1ByZXNlbnRhdGlvbk1vZGVsLmh0bWw=">Presentation Model</a> (aka MVVM) are all good design approaches.  There&#8217;s little merit in debating which precise pattern is &#8220;best&#8221; – if it were that simple then Martin Fowler would have told us the answer by now.  The most important thing is that you should be able to build your widgets with the appropriate degree of composability, isolation and testability.</p>
<p>All MVC-derivatives leverage the observer pattern, and it&#8217;s crucial to choose an implementation to support the right level of decoupling (such as pub/sub).  For example, a web application typically comprises a layout manager which houses its widgets and manages screen real estate, and you will need to consider how your component-level widgets will communicate with application-level code.</p>
<p>You may decide to use additional utilities to implement structural patterns in your application, but you need to proceed with caution.</p>
<p><strong>Toolkit Selection</strong></p>
<p>JavaScript toolkits come in two categories: widgets and utilities.  Utilities such as <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5wcm90b3R5cGVqcy5vcmcv">prototype.js</a> and <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RvY3VtZW50Y2xvdWQuZ2l0aHViLmNvbS9iYWNrYm9uZS8=">backbone.js</a> can serve as the basis for building your own widgets, but that starting point doesn’t suit everyone.</p>
<p>The lack of JavaScript standards means that, invariably, widget toolkits come with their own JavaScript extensions that are both integral to the widgets themselves and also feature in the API.  Combining widgets from more than one toolkit requires special care, and each toolkit brings its own idiosyncratic syntax.  For example, jQuery has its own $() selector syntax, and underscore.js which (as suggested by its name) entirely revolves around the &#8216;_&#8217; symbol.  This can be quite distracting when trying to standardise development across an enterprise.</p>
<p>For each toolkit you adopt, ensure that the benefits outweigh the incremental burden that you are taking on, and ensure that you are happy to embrace its idioms and syntax.</p>
<p>At Caplin we’ve made enthusiastic use of toolkits such as ExtJS, jQuery and Emprise charting, but have found it necessary to build our own frameworks for layout management, real-time grids and templating/data-binding.  The last one of these has proved so useful that we are planning to open source this in the near future.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=4417" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/12/01/html5-toolkits-for-complex-web-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testing APIs for Backwards Compatibility</title>
		<link>http://blog.caplin.com/2010/02/19/testing-apis-for-backwards-compatibility/</link>
		<comments>http://blog.caplin.com/2010/02/19/testing-apis-for-backwards-compatibility/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 17:07:22 +0000</pubDate>
		<dc:creator>Ian Alderson</dc:creator>
				<category><![CDATA[QA]]></category>
		<category><![CDATA[Caplin Trader]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=1137</guid>
		<description><![CDATA[A couple of weeks ago, I wrote about Agile Framework Development and the various techniques that we have used here at Caplin to build our APIs in a way that is sympathetic to agile methodologies. One of the key problems with the iterative development of an API is how to...]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago, I wrote about <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=LzIwMTAvMDIvMDIvYWdpbGUtZnJhbWV3b3JrLWRldmVsb3BtZW50Lw==">Agile Framework Development</a> and the various techniques that we have used here at Caplin to build our APIs in a way that is sympathetic to agile methodologies. One of the key problems with the iterative development of an API is how to ensure that it remains backwardly compatible. Although each new release of an API is focussed on providing more functionality, easier use, or increased robustness for its users, those same users want their existing code to continue working when they upgrade.</p>
<p>This article addresses the issue of how to identify, with confidence, whether an API is backwardly compatible or not. As I mentioned previously there are times when an API is just too incorrect to be kept, however the decision for a breaking change must be a deliberate one &#8211; not an accidental one that is typically only discovered when the users of the API find that their existing code no longer works.</p>
<p><span id="more-1137"></span></p>
<h2>Preventing Breaking Changes</h2>
<p>It is easy to tell developers that they should keep an API backwardly compatible, however even with the best of intentions it is possible to introduce subtle changes to the behaviour, particularly if you are refactoring collaborating classes that may not directly be part of the public interface. Every developer should be aware of the importance of keeping the API backwardly compatible, however this cannot be relied upon. After all, every developer should be striving to keep their code bug free, but we still write tests to verify this.</p>
<p>The solution is to detect any API changes before it is released, preferably in an automated fashion, so that it can be fixed. The problem is how to know whether an API has actually changed.</p>
<p><strong>Compilation</strong></p>
<p>A starting point for a compiled language, such as Java, is whether some code that was written against the old API still compiles against the new one. Any interfaces that have changed, including those with changes to method signatures and so on, will be flagged up immediately by the compiler. However this is no guarantee that the behaviour of the API hasn&#8217;t changed, and this simple verification isn&#8217;t available for non-compiled languages like JavaScript.</p>
<p><strong>Unit Tests</strong></p>
<p>The next obvious tool to detect a change are unit tests. The problem with this is that the unit tests will also be updated when the underlying code is modified. The fact that a unit test for a public API is having to be changed should start alarm bells ringing for the developer making the change; are the changes that they are making backwardly compatible or not? Again, however, the problem with this is that sometimes the changes can be subtle and the breaking change may be missed, particularly if the changes are made to a collaborating class rather that the one that is directly part of the public API.</p>
<p><strong>Acceptance Tests</strong></p>
<p>Acceptance tests can be used to detect breaking changes in a similar way to the unit tests. My problem with this approach is that they tend to be less granular and therefore susceptible to missing subtle breaking changes. Ideally I want my tests for API changes to have excellent coverage and to test all possible code paths, which is usually something that isn&#8217;t done by acceptance tests.</p>
<p><strong>API Tests</strong></p>
<p>Taking a step back, it does look like unit tests seem a good match for solving this particular problem. The only issue is that the unit tests will be modified when the code is changed, which may mask any breaking changes that have unwittingly been introduced. However we do have a set of unit tests perfectly suited to this which haven&#8217;t been modified, those from our previous release. We know that they proved the API for that release worked, so if the same tests pass against the new code it stands to reason that we should be backwardly compatible.</p>
<h2>Creating API Tests</h2>
<p>At Caplin we have a set of API tests that are a specialised group of unit tests aimed at verifying that all aspects and behaviours of the public API have not changed. They are usually a subset of the unit tests written for a particular library.</p>
<p><strong>Only Running the API Tests</strong></p>
<p>The first problem is specifying which tests are those for the API and which are standard unit tests. This is important since the implementation of collaborating classes can be changed without impacting the public API. As a result the old unit tests for refactored collaborating classes may now fail, however these are unimportant if they have no impact on the API.</p>
<p>Within our JavaScript unit tests we have added the ability to flag a particular test as an API test. We can specify whether we want to run only the API tests or all the tests, including the API tests.</p>
<p>Alternate approaches would be to create different test suites for the API and standard tests, or perhaps to use a custom annotation like <code>@ApiTest</code> rather than <code>@Test</code> in <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5qdW5pdC5vcmcv">JUnit 4</a>.</p>
<p><strong>Dangers With Mocking</strong></p>
<p>One danger with testing APIs is the use of <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5tb2Nrb2JqZWN0cy5jb20v">mock objects</a>. Mock objects combined with <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9EZXBlbmRlbmN5X2luamVjdGlvbg==">dependency injection</a> provide a powerful way to test the logic of a particular piece of code as a single unit, without having to rely on the real logic in the collaborating objects. Instead the mock object acts as a replacement for the real collaborating object, verifying that it is invoked in the correct way and returns the appropriate values.</p>
<p>The danger is that changes to the collaborating object, such as the addition of a statement that throws a runtime exception if an argument is null, will not be emulated by the mock object. These problems are not insurmountable, however you need to be aware of the potential risks. In the case above there is a reasonable argument that there should have been an API test written for the collaborating class that demonstrated that the arguments could have been null previously which would now fail.</p>
<p><strong>Getting the API Tests</strong></p>
<p>At Caplin we upload the API tests to our <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21hdmVuLmFwYWNoZS5vcmcv">Maven</a> repository along with the other build artifacts for our libraries. For example when we release version 1.0 of a library, the API tests for 1.0 are uploaded to Maven. When we are building version 1.1 of the library we download the API tests for 1.0 to verify that the API has not changed.</p>
<p>Alternatives to getting the tests from Maven are to use another dependency management system, to pull the tests from a branch or label from source control, or even copying them from a network share.</p>
<p><strong>Updating API Tests</strong></p>
<p>It is possible that a public API hasn&#8217;t changed, however the API test for it fails. The reason for this could be that the interaction between the API method and its collaborating objects, particularly if they have been mocked out, have changed, and the test expectations are no longer valid. As a result the code for the API tests will need to be updated.</p>
<p>This change needs to be managed via source control, with a new version of the API tests pushed into Maven, or wherever they are being stored.</p>
<p><strong>Backward Compatibility With Older Versions</strong></p>
<p>At the moment we are only checking backward compatibility against the previous version of the API. I believe that if an API is compatible with the previous one, and that previous one was compatible with the one before, and so on, then it stands to reason that the current API should be compatible with the oldest one.</p>
<h2>Conclusions</h2>
<p>We are still in the early days of trying out this approach, however the early signs have been encouraging.</p>
<p>Ultimately a large amount of the responsibility still lies with developers to ensure that their code changes to a public API maintain backwards compatibility. The API tests are a safety net that gives confidence that it really is backwardly compatible and provide an early warning of any breaking changes, allowing them to be fixed before a release is made.</p>
<p>Any breaking changes within an API must be a conscious decision, not an inadvertent one.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1137" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/02/19/testing-apis-for-backwards-compatibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an Observer to an Observable</title>
		<link>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/</link>
		<comments>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 13:00:24 +0000</pubDate>
		<dc:creator>Ian Alderson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Caplin Trader]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Observer]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=111</guid>
		<description><![CDATA[The Observer design pattern is used in many applications. If you are unfamiliar with it, or need to remind yourself about the specifics, you can read about it at Wikipedia or MSDN. Caplin Trader even provides a helper class to take care of a lot of the boiler plate code: caplin.core.Observable. The...]]></description>
			<content:encoded><![CDATA[<p>The Observer design pattern is used in many applications. If you are unfamiliar with it, or need to remind yourself about the specifics, you can read about it at <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9PYnNlcnZlcl9wYXR0ZXJu">Wikipedia</a> or <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9lbi11cy9saWJyYXJ5L21zOTU0NjIxLmFzcHg=">MSDN</a>. Caplin Trader even provides a helper class to take care of a lot of the boiler plate code: <em>caplin.core.Observable</em>.</p>
<p>The purpose of the Observer design pattern is to allow one object to notify other objects of events &#8211; usually to do with changes to its state. One common problem I have encountered however is what to do when an Observer  is first registered, since the object that it is observing may already be in a particular state.</p>
<p><span id="more-111"></span></p>
<p>There are two obvious approaches to this problem.</p>
<ol>
<li>The object registering the Observer must check what the state of the object it wants to Observe is after the registration and handle the implications of this (e.g. enabling/disabling parts of the GUI). The main issue I have with this is that it can mean that I end up with two code paths, one to do something before the Observer has been registered and one for the event notifications. In the case where there are lots of different types of Observers for the same object this will introduce a lot of extra code paths &#8211; and eventually someone is bound to forget to handle the initial state and thus introduce a bug. In a multi-threaded environment this may become more complicated, particularly if you want to ensure that you only receive an event once.</li>
<li>When the Observer is registered it is notified of the current state of the object it is observing. Although this is not a standard part of the design pattern, I have found it useful since you only have one code path within the Observer for handling the events.</li>
</ol>
<p>The following example demonstrates how the second approach can easily be implemented in JavaScript (using caplin.core.Observable).</p>
<pre class="javascript">caplin.namespace("caplinx");

caplin.include("caplin.core.Observable");

caplinx.Trade = function()
{
   this.m_bExecuted = false;
   this.m_oObservable = new caplin.core.Observable();
};

caplinx.Trade.prototype.addTradeListener = function(oListener)
{
   this.m_oObservable.addObserver(oListener);

   // **********************************************
   // if we have already executed the trade notify the newly added
   // listener immediately
   if (this.m_bExecuted)
   {
      oListener.executed();
   }
   // **********************************************
};

caplinx.Trade.prototype.execute = function()
{
   // code to handle trade execution ...

   this.m_bExecuted = true;

   // notify all listeners that the trade has executed
   this.m_oObservable.notifyObservers("executed");
}</pre>
<p>The technique suggested here is not necessarily appropriate for all Observer design pattern implementations, however I have found it useful to consider when I am writing a new class that will be observed by others.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=111" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

