<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5437932071029458618</id><updated>2012-02-28T12:53:56.656-08:00</updated><category term='Computational Theory'/><category term='Design Patterns'/><category term='Engineering Practices'/><category term='Enterprise Architecture'/><title type='text'>On Software Engineering</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sal-razzaq.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-8882955152287366624</id><published>2011-01-19T11:21:00.000-08:00</published><updated>2011-01-19T11:39:56.264-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>Model-View-Presenter (MVP)</title><content type='html'>The main purpose of the Model-View-Presenter (MVP) design pattern is to separate domain and application-specific logic (the Model) from the user interface (the View) of the application. The advantages of this separation of concerns are three-fold:&lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;Domain logic is not dispersed in the user interface code. When domain logic is strongly coupled with the user interface code, there is a high likelihood of code duplication. Less duplication facilitates debugging, maintenance, enhancements and promotes code reuse.&lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;The user interface can be changed independently of the Model in many cases where the application requirements have not fundamentally changed. For example, to enhance usability it may be desirable to change a spin control to a slider control. Similarly, the actual implementation of the Model may be changed to use a different persistence model or to use a smarter algorithm&lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Last but not least, the separation of domain logic from the user interface greatly facilitates unit testing of the code.&lt;br /&gt;&lt;br /&gt;Now that we have established the goals and benefits of separating domain and application-specific logic (the Model) from the user interface (the View), let’s delve into how MVP design pattern is useful. It is noteworthy that there are several variations of MVP and its predecessor Model-View-Controller (MVC) design pattern. For the purpose of this discussion, we will let our intuition derive a practical variant of MVP. To begin, we pose this question: Based on the goals and benefits of separating domain and application-specific logic from the user interface, what are some of the desirable attributes of an implementation? We explore this question through a few concrete examples:&lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;We want to be able to change the gadgets and controls used on the View without massive refactoring of the code.&lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;We want to be able to use a desktop database for one version of our application and a client-server database for another version of our application without having to duplicate too much code.&lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Based on a user, we want to display only certain fields on the View.&lt;br /&gt;&lt;br /&gt;4.&amp;nbsp;For an advanced user we want multiple views to show the same information in different ways (for example, a chart and a grid). We want these views to remain synchronized when any of the views are updated.&lt;br /&gt;&lt;br /&gt;It is evident from the examples above that we need a degree of separation between the View and the Model. This is where the Presenter comes into the picture. Presenter is essentially the go-between the View and the Model. So what would we expect a Presenter to do? Here are some common tasks suited for the Presenter:&lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;Create and display the View&lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;Obtain data from the Model and pass it along to the View for display to the user&lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Be aware when a User modifies data on the View. Presenter may need to update the Model or ask the Model for recalculation of some sort. Presenter may need to update some other portion of the View as a result. The View handles basic user interaction (processing of keystrokes to accept data from the user) whereas the Presenter is responsible for making application-specific responses (update the Model and triggering a recalculation).&lt;br /&gt;&lt;br /&gt;Now let’s examine some things the players in the MVP implementation must not do:&lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;Presenter must not call or manipulate the widgets (controls) on the View directly. We want the ability to swap one implementation of the View with another. If the Presenter called methods on the widgets (controls) directly, this ability will be compromised. &lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;View must not manipulate the Model directly. Recall it is the job of the Presenter to marshal the data between the Model and View. This might seem a bit cumbersome but in the bigger scheme of things it is desirable to separate the Model from the View. For example, if there is a need to change the Model later, we will need to change the Presenter and the View code as apposed to just the Presenter code.&lt;br /&gt;&lt;br /&gt;We now see dependencies and interactions developing among the players in an MVP implementation:&lt;br /&gt;&lt;br /&gt;1.&amp;nbsp;Presenter relies on the View and the Model. Presenter is responsible for preparing and formatting the data suitable for display by the View. The Presenter provides this data to the View through a well-defined interface. The View is responsible for actual visualization of data for the user. The Presenter is also responsible for retrieving any modified data from the View. The Presenter is responsible for preparing and formatting the data suitable to be passed onto the Model for further processing or persistence. Again, the data is passed to the Model through a well-defined interface.&lt;br /&gt;&lt;br /&gt;2.&amp;nbsp;The implementation of the View and the Model shall remain independent of the Presenter. To achieve this, we need well-defined interfaces for the View and the Model that the Presenter can talk to. Any View or Model that implements an interface expected by a Presenter can be readily plugged into implementation.&lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;The Presenter is also an observer of the events that occur in the View and the Model. Consequently, the View and the Model must publish events that the Presenter can subscribe to. For example, a Presenter may subscribe to a new user data entry event published by the View. Upon receiving notification of such an event, a Presenter may update the Model. A Presenter may also subscribe to data change event published by the Model. For example, if the Model changes due to some outside operation, the Presenter is made aware of the change and can accordingly update the View. Using this mechanism, a Presenter can even manage multiple Views and keep them synchronized.&lt;br /&gt;&lt;br /&gt;Figure 1 summarizes the dependencies discussed above.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTc8lwtrHfI/AAAAAAAAABk/CDvMYTUKqXw/s1600/mvp_figure1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="153" n4="true" src="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTc8lwtrHfI/AAAAAAAAABk/CDvMYTUKqXw/s320/mvp_figure1.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;To be precise, the Presenter interacts with a Model and View that implement interfaces expected by the Presenter. We call these interfaces IModel and IView, respectively in Figure 2. Any View or Model that implements the interfaces expected by the Presenter can be plugged into the implementation.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_fxCRF7Hb_I4/TTc9JK0CoLI/AAAAAAAAABo/9Bltl4ojt4c/s1600/mvp_figure2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="190" n4="true" src="http://3.bp.blogspot.com/_fxCRF7Hb_I4/TTc9JK0CoLI/AAAAAAAAABo/9Bltl4ojt4c/s320/mvp_figure2.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Finally, let’s put everything together. We begin with construction of a Presenter object. The Presenter object either takes a View and a Model object as arguments in its constructor or instantiates these objects in the constructor. Usually there is a method called Initialize() on the Presenter object that sets the wheels in motion. Presenter.Intialize() creates the View and provides data to the View obtained from the Model. The Presenter then displays the View to the user. The Presenter also subscribes to events of interest published by the View and the Model. Upon receiving such events, the Presenter takes appropriate actions such as updating portions of a View or updating the Model. &lt;br /&gt;&lt;br /&gt;Figure 3 shows a sequence diagram summarizing what happens when a user updates data on a View.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTc9c7aiblI/AAAAAAAAABs/JJZJJW_epdc/s1600/mpv_figure3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="195" n4="true" src="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTc9c7aiblI/AAAAAAAAABs/JJZJJW_epdc/s320/mpv_figure3.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The user enters data in one of the controls displayed by the View. The View notifies the Presenter of this data entry. The Presenter asks the View for the updated value. Finally, the Presenter formats this data appropriately and passes it onto the Model for persistence.&lt;br /&gt;&lt;br /&gt;Figure 4 shows how the Presenter reacts when the Model is changed externally.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_fxCRF7Hb_I4/TTc9fvSi3bI/AAAAAAAAABw/HZ5aLN9DKLs/s1600/mvp_figure4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="178" n4="true" src="http://3.bp.blogspot.com/_fxCRF7Hb_I4/TTc9fvSi3bI/AAAAAAAAABw/HZ5aLN9DKLs/s320/mvp_figure4.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;A change is detected by the Model as a result of an outside operation such as an update to the database or an update to the Model by another component. The Model notifies the Presenter of the change. The Presenter obtains the updated data from the Model. The Presenter properly formats the data and passes it onto the View for display to the user. Note if the Presenter is managing multiple Views, the Presenter is in an excellent position to update and synchronize all the Views it is managing.&lt;br /&gt;&lt;br /&gt;The apparent disadvantage of using MVP is the extra coding involved in separating the Model, View and Presenter. However, for most applications that involve user interaction, time invested in implementing MVP is well worth the benefits that come with separating domain and application-specific logic from the user interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-8882955152287366624?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8882955152287366624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8882955152287366624'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/model-view-presenter-mvp.html' title='Model-View-Presenter (MVP)'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTc8lwtrHfI/AAAAAAAAABk/CDvMYTUKqXw/s72-c/mvp_figure1.jpg' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-3780855750886825142</id><published>2011-01-18T16:04:00.000-08:00</published><updated>2011-01-18T16:05:46.053-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Dimensions of Software Testing</title><content type='html'>As Agile developers, we are most accustomed to writing Unit Tests for our code. There is a lot more to software testing than Unit Testing alone. In order to release a robust software product, we need to devise and implement tests to cover other dimensions of software as well. Testing can be can be sliced in various ways. The following are several different ways to view software testing.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Purpose&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Correctness&lt;/li&gt;&lt;li&gt;Scalability&lt;/li&gt;&lt;li&gt;Performance&lt;/li&gt;&lt;li&gt;Load (Stress)&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Granularity&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Unit&lt;/li&gt;&lt;li&gt;Functional&lt;/li&gt;&lt;li&gt;Integration&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Tier&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;User Interface&lt;/li&gt;&lt;li&gt;Business&lt;/li&gt;&lt;li&gt;Service&lt;/li&gt;&lt;li&gt;API&lt;/li&gt;&lt;li&gt;Database&lt;/li&gt;&lt;/ol&gt;&amp;nbsp; &lt;br /&gt;&lt;span style="font-size: large;"&gt;Proof&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Positive&lt;/li&gt;&lt;li&gt;Negative&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Environment&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Operating System&lt;/li&gt;&lt;li&gt;Database Server&lt;/li&gt;&lt;li&gt;Application Server&lt;/li&gt;&lt;li&gt;Web Server&lt;/li&gt;&lt;li&gt;Browser&lt;/li&gt;&lt;li&gt;Runtime, Virtual Machine&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&lt;span style="font-size: large;"&gt;Scope&lt;/span&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;Smoke&lt;/li&gt;&lt;li&gt;Regression&lt;/li&gt;&lt;li&gt;Full&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Deployment&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;New &lt;/li&gt;&lt;li&gt;Existing (Upgrade)&lt;/li&gt;&lt;li&gt;Various Platforms&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-3780855750886825142?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3780855750886825142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3780855750886825142'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/dimensions-of-software-testing.html' title='Dimensions of Software Testing'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-632990274280855533</id><published>2011-01-18T15:59:00.000-08:00</published><updated>2011-01-18T16:01:24.196-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Three things all Units Tests must do</title><content type='html'>Unit Tests verify correctness of a discrete piece of code. Regardless of the application domain and the unit test tools utilized, there are three things a well-written unit test must do:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create and verify prerequisite state for the action to be tested&lt;/li&gt;&lt;li&gt;Execute the action to be tested&lt;/li&gt;&lt;li&gt;Verify post-action state&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Example&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Let's say we have a system that allows warehouse employees to ship products. A ShippingOrder is an object in the system that contains the products to be shipped. Our business rule states that a ShippingOrder can only be processed (shipped) if all products in the ShippingOrder are in stock. In other words, we want to verify that either all products in a ShippingOrder are shipped or none of the products in the ShippingOrder are shipped based on stock availability. Our Unit Test will verify this behavior of the ShippingOrder.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;1. Create and verify prerequisite state&lt;/span&gt; &lt;br /&gt;&lt;div&gt;Before a test is executed, we want to ensure that the environment in which a test is about to be executed is known and verified. It is important to stress that it is not sufficient to bring the test environment into a known state but also to explicitly verify the state before execution of the action. This is typically done using ASSERTs provided by the Unit Testing framework. In our example, we have at least three stock level conditions: &lt;/div&gt;S_1. All Products in the ShippingOrder are in stock &lt;br /&gt;&lt;div&gt;S_2. None of the Products in the ShippingOrder are in stock&lt;/div&gt;&lt;div&gt;S_3. Some the products in the ShippingOrder are in stock&lt;/div&gt;We have identified three states of product stock levels and hence we will be executing at least three tests. Before each of the three tests is executed, the corresponding state of the stock levels of products in the ShippingOrder must be established and verified by our test setup code. Our test code will create three distinct ShippingOrder objects corresponding to these states. Lets call these objects SO_1, SO_2, and SO_3. The test setup code must also verify that these three ShippingOrder objects are in Pending state.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;2. Execute the test &lt;/span&gt;&lt;br /&gt;Our test is going to verify that a ShippingOrder can only transition to a Shipped state when our business rules are satisfied. We will be writing at least 3 actions:&lt;br /&gt;&lt;br /&gt;T_1. Use SO_1. Try to transition ShippingOrder to a Shipped state. &lt;br /&gt;&lt;div&gt;T_2. Use SO_2. Try to transition ShippingOrder to a Shipped state.&lt;/div&gt;&lt;div&gt;T_3. Use SO_3. Try to transition ShippingOrder to a Shipped state.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;3. Verify post-action State&lt;/span&gt; &lt;br /&gt;&lt;div&gt;Once the test action is executed, we verify the post-action state of SO_1, SO_2, and SO_3 using ASSERTs provided by the Unit Testing framework:&lt;br /&gt;&lt;/div&gt;V_1. Verify SO_1 is in Shipped state &lt;br /&gt;&lt;div&gt;V_2. Verify SO_2 is in Pending state&lt;/div&gt;&lt;div&gt;V_3. Verify SO_3 is in Pending state&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-632990274280855533?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/632990274280855533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/632990274280855533'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/three-things-all-units-tests-must-do.html' title='Three things all Units Tests must do'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-7858279206033436691</id><published>2011-01-18T15:52:00.000-08:00</published><updated>2011-01-18T15:55:04.186-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enterprise Architecture'/><title type='text'>SOA Application Blueprint</title><content type='html'>Here is a simple blueprint for building an application based on the Service Oriented Architecture (SOA). &lt;br /&gt;&lt;br /&gt;The various participants in this architecture are as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTYoUBXe-bI/AAAAAAAAABg/TlB9EdLKwpU/s1600/soa_blueprint.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="253" n4="true" src="http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTYoUBXe-bI/AAAAAAAAABg/TlB9EdLKwpU/s320/soa_blueprint.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Application Domain Layer (ADL)&lt;/span&gt;&lt;br /&gt;ADL is where the business logic or the brains of the application resides. ADL is the most valuable piece of this architecture. ADL should closely model the business entities, processes, and workflows without regard to data persistence or the user interface. ADL should be testable in isolation. Full suite of unit, functional and regression tests must be maintained and continuously executed. To isolate ADL from the Data Persistence Layer (DPL), a Data Persistence Adapter (DPA) is introduced.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Data Persistence Adapter (DPA)&lt;/span&gt;&lt;br /&gt;DPA implements a well-defined interface that ADL uses to persist itself. A concrete implementation of DPA makes specific calls to the Data Persistence Layer (DPL) to do the actual saving and loading the of the data. A concrete, mock DPA should be written that emulates known data save and load behaviors. The mock DPA can be utilized by the ADL Test Suite to exercise the functionality of ADL on an ongoing basis.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Data Persistence Layer (DPL)&lt;/span&gt;&lt;br /&gt;In most system implementations, this is the relational database management system such as Oracle, Microsoft SQL or equivalent. ADL never talks to DPL directly. Only Data Persistence Adapter (DPA) has direct interaction with Data Persistence Layer (DPL) usually through ODBC, JDBC, or a .NET Data Provider.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Application Service Layer (ASL)&lt;/span&gt;&lt;br /&gt;ASL is the immutable interface to the System. The existing service methods and data contracts of ASL are never changed once published. However, new service interfaces, methods and data contracts can be added to extend the functionality of the application. The primary consideration in the design of this layer is the ease and efficiency of consumption of ASL Services by its clients such as the Application Presentation Layer (APL) and the Batch and External Systems (BES).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Application Presentation Layer (APL)&lt;/span&gt;&lt;br /&gt;APL is the user interface of the application. It usually takes form of a Web Site or a Desktop Application. APL never calls ADL, DPA, or DPL directly. It does all data querying and manipulation through the Application Service Layer (ASL).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Batch and External Systems (BES)&lt;/span&gt;&lt;br /&gt;An application may require offline, asynchronous, or batch processing. Furthermore, external systems may need to access the System to query or update data. Like APL, BES never calls ADL, DPA, or DPL directly. It does all data querying and manipulation through the Application Service Layer (ASL).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-7858279206033436691?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7858279206033436691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7858279206033436691'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/soa-application-blueprint.html' title='SOA Application Blueprint'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_fxCRF7Hb_I4/TTYoUBXe-bI/AAAAAAAAABg/TlB9EdLKwpU/s72-c/soa_blueprint.jpg' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-5820245141946912746</id><published>2011-01-18T15:49:00.000-08:00</published><updated>2011-01-18T15:51:12.391-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enterprise Architecture'/><title type='text'>Using Queues to improve performance and reliability</title><content type='html'>Enterprise Systems typically involve two or more applications that collaborate with each other to run a business process. One of the ways that participants of an Enterprise System can share information is queuing. Logically speaking, queues are a system resource where applications in an Enterprise System can place messages for each other. Microsoft Message Queuing (MSMQ) is an example of such a queue.&lt;br /&gt;&lt;br /&gt;Message queues provide a repository for inter-application messages and ensure guaranteed delivery of messages. In MSMQ, a queue may be defined as a transactional queue ensuring that the messages are enqueued, and hence dequeued and delivered, in the original order. Furthermore, a transactional queue persists each message received to ensure guaranteed delivery in case of a system crash.&lt;br /&gt;&lt;br /&gt;Queues are useful in many Enterprise System scenarios. These scenarios have one thing in common: one application places a message in the queue and another application picks up the message from queue and acts on it. This allows us to distribute work among applications in an Enterprise System. Queues can also improve throughput of an Enterprise System. &lt;br /&gt;&lt;br /&gt;Let's consider a stock order processing system that receives a stock order from client applications through a web service call to an endpoint it hosts. The orders must be processed in the order they are received and must not be lost. During peak trading hours of trading, it is likely that the stock order processing system will be receiving orders at a much higher speed than it can process them. In a monolithic, single-threaded stock order processing system, the throughput of the stock ordering system is constrained by the speed at which it can process the orders. Granted to improve performance we can spin two threads: one to receive orders and the other to process the order. But to ensure guaranteed delivery and in-order processing of stock orders received we will have to cook up our own scheme.&lt;br /&gt;&lt;br /&gt;Now consider how we can design the stock order processing system more elegantly using queues. Our System will have three components:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Transactional Queue&lt;/li&gt;&lt;li&gt;Listener Application&lt;/li&gt;&lt;li&gt;Order Processing Application&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Transactional Queue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;A transactional queue can be created using MSMQ.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Listener Application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The job of the listener application is to simply host the endpoint for the receiving the stock order requests and to enqueue these requests as messages into the Transactional Queue.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Order Processing Application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The job of the Order Processing Application is to dequeue a message from the Transactional Queue and to act on it (i.e. to route stock orders to an external trading system).&lt;/div&gt;Some of the benefits of this queue-based design are follows:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Stock orders delivered guaranteed because of the Transaction Queue&lt;/li&gt;&lt;li&gt;Stock orders are processed in the order they are received because of the Transaction Queue&lt;/li&gt;&lt;li&gt;The Listener Application continues to enqueue Stock Order messages even if the Order Processing Application goes down or can't keep up with the rate at which the stock orders are being received&lt;/li&gt;&lt;li&gt;We are able to scale Order Processing Application up (more powerful machine) or out (more machines) to improve throughput of the stock order processing system&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-5820245141946912746?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5820245141946912746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5820245141946912746'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/using-queues-to-improve-performance-and.html' title='Using Queues to improve performance and reliability'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-5389155454279706992</id><published>2011-01-18T15:45:00.000-08:00</published><updated>2011-01-18T15:45:54.660-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enterprise Architecture'/><title type='text'>Enterprise Application Integration Patterns</title><content type='html'>&lt;span style="font-size: large;"&gt;Messaging Pattern&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Applications participating in an Enterprise Solution communicate with each other using a common messaging system. The message publishing application follows the fire and forget model where it places a message in the shared messaging system and forgets about it. Other interested applications listen for these messages and act on them as business rules dictate. The most common implementation of a messaging system is a queue. The queue semantics ensure delivery of messages in the order they are received. A robust messaging system guarantees delivery via local persistence of message and multiple delivery attempts. The delivery guarantee is important because all participant applications in an Enterprise Solution may not be online all the time. Microsoft Message Queuing (MSMQ) and Oracle Advanced Queues are examples of messaging systems.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Shared Database Pattern &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If all applications participating in an Enterprise Solution have access to a common database, the applications can exchange data by reading/writing to the common database. This is a less robust solution than the Messaging Pattern because a change in the common database schema may require modifications to participating applications.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Service Oriented Architecture (SOA) Pattern&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The applications participating in an Enterprise Solution expose their functionality as a Public API that other applications can consume. This approach is more robust than sharing a database but still causes some coupling between applications due to dependence on the Public API. There is also an implicit assumption that all collaborating applications are online all the time. The most common incarnation of SOA are SOAP and RESTful Web Services.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Shared File Pattern&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this pattern, the publishing application writes a file with appropriate data and/or instructions to a shared network resource. The interested applications read this file and act on it as appropriate. On the surface, this approach seems to be a highly decoupled and robust. However, for a complex application this method of collaboration can be cumbersome and requires agreement on content location, file access policies, shared file disposal, frequency of file drops and retrievals, and meaning of the file content and format.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Messaging + SOA Pattern &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For a complex Enterprise Solution with many participating Applications, Messaging provides the most robust solution. Messaging Pattern is even more effective when it is used as a way to communicate Commands among participating applications rather than detailed application data. Following the preceding paradigm, the Messaging Pattern can be combined with the SOA Pattern. For example, let's say an Enterprise Solution consists of an Accounting Application and a Shipping Application. When a payment is received from the customer for an order, the Accounting Application publishes a message stating that an order is OK to ship. The message contains the May Ship Order command with an additional parameter Order Id (Messaging Pattern). When the Shipping Application receives the message, it calls the Public API of the Accounting Application (SOA Pattern) to get the details of the order to ship and proceeds with shipping.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-5389155454279706992?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5389155454279706992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5389155454279706992'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/enterprise-application-integration.html' title='Enterprise Application Integration Patterns'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-9091531871721875996</id><published>2011-01-18T15:41:00.000-08:00</published><updated>2011-01-18T15:41:36.103-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>Strategy Pattern</title><content type='html'>&lt;span style="font-size: large;"&gt;What&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Encapsulate a family of algorithms or behaviors into a set of interchangeable classes. The algorithm/behavior classes are made interchangeable via concrete implementations against a common algorithm/behavior interface.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Why&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The algorithm/strategy classes can be modified independent of the classes that use them as long as they adhere to the original interface they implemented.&lt;br /&gt;Code duplication is minimized because the same algorithm or behavior does not need to be implemented in each individual class that needs to have that algorithm/behavior.&lt;br /&gt;The algorithm/behavior of the classes can be dynamically set at runtime via constructor injection or a setter property.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;How&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Say we need to apply a promotional discount to the total invoice amount. The promotional discount can vary based on the marketing campaign in effect.&lt;br /&gt;interface IPromoDiscount&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; decimal ApplyDiscount(decimal amount);&lt;br /&gt;}&lt;br /&gt;// The logic to apply discount is encapsulated here&lt;br /&gt;class PromoDiscount : IPromoDiscount&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; decimal m_DiscountRate;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; private PromoDiscount() {}&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; public PromoDiscount(decimal discountRate)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_DiscountRate = discountRate;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; public decimal ApplyDiscount(decimal amount)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (amount * (1 - m_DiscountRate));&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Invoice&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; // invoice does not know about the real implementation&lt;br /&gt;&amp;nbsp; // of IPromoDiscount&lt;br /&gt;&amp;nbsp; IPromoDiscount m_PromoDiscount;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; private Invoice() {}&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; // Injecting the 'algorithm' to calculate discount&lt;br /&gt;&amp;nbsp; public Invoice(IPromoDiscount promoDiscount)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_PromoDiscount = promoDiscount;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; private decimal CalculateSumOfAllInvoiceLines()&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; public decimal InvoiceTotal&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_PromoDiscount.ApplyDiscount(CalculateSumOfAllInvoiceLines());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;// Specify the discount to apply for an Invoice&lt;br /&gt;// The same Invoice class can be used without modification&lt;br /&gt;// for all three discount scenarios&lt;br /&gt;Invoice invoiceNoDiscount = new Invoice(new PromoDiscount(0M));&lt;br /&gt;Invoice invoiceWithTenPercentDiscount = new Invoice(new PromoDiscount(0.10M));&lt;br /&gt;Invoice invoiceWithTwentyPercentDiscount = new Invoice(new PromoDiscount(0.20M));&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-9091531871721875996?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/9091531871721875996'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/9091531871721875996'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/strategy-pattern.html' title='Strategy Pattern'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-3140234582410626609</id><published>2011-01-18T15:38:00.000-08:00</published><updated>2011-01-18T15:38:38.268-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>OO Concepts - Abstraction, Inheritance, Polymorphism, Encapsulation (AIPE)</title><content type='html'>&lt;span style="font-size: large;"&gt;Abstraction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Abstraction is describing the essential and omitting the irrelevant. Abstraction principle is used when modeling the problem domain using class objects and the interaction between these class objects. Abstraction implores us to describe our design in terms of the problem domain instead of getting bogged down in implementation details.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Inheritance&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Inheritance is a mechanism whereby the functionality of existing (base) classes is reused by new (derived) classes. Inheritance allows us to share the data and behavior of one abstraction into another. The derived class reuses the behavior of the base class and overrides such behavior when necessary to create a specialized version of the base class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Polymorphism&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Polymorphism literally means having multiple forms. Using inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. Polymorphism allows a programmer to treat a derived class just like its parent class even though the derived class may have redefined the behavior of its base class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Encapsulation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Encapsulation is the process by which details that do not contribute to its abstraction are hidden. Encapsulation means hiding of information that is not relevant to the outside world. Encapsulation when applied to design of a class is a technique to hide low-level details of the class from the users of the class. Only what is meaningful to the user of the class is exposed through public members. The rest is kept private and can be changed independently of the users of the class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-3140234582410626609?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3140234582410626609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3140234582410626609'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/oo-concepts-abstraction-inheritance.html' title='OO Concepts - Abstraction, Inheritance, Polymorphism, Encapsulation (AIPE)'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-8419740534190258539</id><published>2011-01-18T15:34:00.000-08:00</published><updated>2011-01-18T15:36:16.654-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>OO Principles</title><content type='html'>&lt;span style="font-size: large;"&gt;Encapsulate that varies&lt;/span&gt;&lt;br /&gt;Place functionality that may change into a separate class that can be utilized by other classes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Favor composition over inheritance&lt;/span&gt;&lt;br /&gt;Composition facilitates better reuse of code, results in less code duplication, and has fewer side-effects than inheritance. Instead of defining a common behavior in the base class, encapsulate that behavior in a separate class that can be utilized by classes in the inheritance hierarchy through composition.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Program to interfaces, not implementations&lt;/span&gt;&lt;br /&gt;Encapsulate functionality into a class that implements an interface. The user of the functionality is coded against the interface of the class, not its concrete implementation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Loose Coupling&lt;/span&gt;&lt;br /&gt;When two or more classes or family of classes need to collaborate, share as little implementation details of classes with each other as possible. There are several techniques to achieve loose coupling. For example, program to interfaces instead of concrete class implementations. This allows us to swap class implementations without having to change the code that is written against an interface. When applicable, Observer Pattern is another way to achieve loose coupling where the Subject knows very little about its Observers and begins and ends its relationship with its Observers at runtime.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Open-Closed Principle&lt;/span&gt;&lt;br /&gt;This principle advocates a design that is extensible without having to make modifications to existing code. Decorator Pattern illustrates the application of this principle very well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-8419740534190258539?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8419740534190258539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8419740534190258539'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/oo-principles.html' title='OO Principles'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-7143408949386289479</id><published>2011-01-18T15:30:00.000-08:00</published><updated>2011-01-18T15:32:19.491-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>Application Archetypes</title><content type='html'>&lt;div&gt;&lt;span style="font-size: large;"&gt;Online transaction processing systems - OLTP&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Low latency&lt;/li&gt;&lt;li&gt;High responsiveness&lt;/li&gt;&lt;li&gt;Data integrity&lt;/li&gt;&lt;li&gt;Predefined UI worflows&lt;/li&gt;&lt;li&gt;Examples: crm systems, e-commerce sites, e-banking systems&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Analysis systems - online analytical processing - OLAP&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Produce complex analytical customizable queries&lt;/li&gt;&lt;li&gt;Large multidimensional datasets&lt;/li&gt;&lt;li&gt;Low latency response&lt;/li&gt;&lt;li&gt;Examples: Business intelligence systems&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Batch systems&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Perform operations on large datasets efficiently&lt;/li&gt;&lt;li&gt;Job execution coordination to maximize CPU utilization&lt;/li&gt;&lt;li&gt;Auto recover from exceptions&lt;/li&gt;&lt;li&gt;Examples: Billing systems, provisioning systems&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-7143408949386289479?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7143408949386289479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7143408949386289479'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/application-archetypes.html' title='Application Archetypes'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-7379514214315840914</id><published>2011-01-14T15:38:00.001-08:00</published><updated>2011-01-14T15:39:01.221-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Role of Software Architect in an Agile Environment</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Is the role of Software Architect still relevant in an Agile development shop? Given that Agile methodologies shun big up front design and take design-as-you-go approach, should there be a person or persons designated to look after the system architecture? The answer is unequivocally yes for any system of any significant size. For any significant system, there are key technology decisions that need to be made up front before development can even begin.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;For example, whether the system is going to be a desktop application or a web application? Will it be hosted on Windows or UNIX? Which programming language and class libraries to use? Key technology and architectural approaches must be vetted out carefully before coding can begin. Once coding begins, some architectural oversight has to be in place to ensure the system follows the planned architectural pattern. There is still plenty to do during the development Sprints.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;However, in an Agile environment, a Software Architect must adapt his or her approach towards creating, implementing and overseeing system architecture:&lt;/span&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Live in the moment! Defer decisions to the last responsible moment. Let the architecture emerge. Only decide what needs to be decided right now. Set the direction and let the developers fill in the rest. To maintain oversight, pair program with developers especially in key areas where security, performance and scalability aspects of the application are at stake. In addition, review unit and functional tests.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Consider yourself part of the development team. To garner any respect or following from the development team, an Architect must be an excellent technologist. Absolutely write some production code. This is in addition to developing proof of concepts, prototypes, design patterns, and perhaps some base classes to kick start the development. At the outset of a new system (or subsystem) development, an Architect must validate the approach by creating a skeletal version of the application that hits all key technologies that will be utilized and simulate all application tiers that would be deployed in the production system.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Communicate in the language of the developers (e.g. class diagrams, code examples, whiteboard, not PowerPoint slides). High level artifacts do not resonate well with developers who are focused on what needs to be done right now to complete stories in the current Sprint. Maintain a development WIKI where engineers can document significant design decisions. For one, this makes engineers think harder about the design decision they are making and perhaps just as importantly provides some continuity as different Agile teams work on the same feature over time.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;On top of all of the above, an Architect must have the temperament and patience to listen and balance the needs of all stakeholders. An Architect must be able to effectively communicate the system design, at different levels of detail, to internal (e.g. sales, marketing, documentation, executive team) and external stakeholders (e.g. users, customer leadership team, customer IT department) and explain how the system design meets everyone's business goals.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-7379514214315840914?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7379514214315840914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/7379514214315840914'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/role-of-software-architect-in-agile.html' title='Role of Software Architect in an Agile Environment'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-799245914606835943</id><published>2011-01-14T15:35:00.001-08:00</published><updated>2011-01-14T15:37:20.708-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Source Code Branching for Release Management</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;1. When features targeted for a particular release are code complete, a RELEASE branch is created. All fixes and changes including service packs for the release are made in this branch. The system is built and released from this branch.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;2. Changes for future versions of the system can continue to be made in the MAIN line while fixes are being made in a RELEASE branch to service live customers. Any fixes made in the RELEASE branch that are applicable to the code in the MAIN line can be merged from the RELEASE branch to the MAIN line.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://razzaq.org/pub/sourcecontrol_release_mgmt.gif" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-799245914606835943?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/799245914606835943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/799245914606835943'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/source-code-branching-for-release.html' title='Source Code Branching for Release Management'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-8861753182165054027</id><published>2011-01-14T15:33:00.001-08:00</published><updated>2011-01-14T15:34:40.218-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Writing effective stories for a Scrum Sprint</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;A Story is a brief narration of a software requirement that describes desired functionality in terms of business value it brings to the Customer. A story is best expressed in terms of a Customer Goal. For example, compare the following two different ways of expressing the same requirement:&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: large;"&gt;Form 1:&lt;/span&gt; Implement a query system to lookup inactive customers for a region.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: large;"&gt;Form 2:&lt;/span&gt; As a Regional Director, I would like to periodically find out which customers have been inactive for more than 30 days.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;It can be argued that Form 2 is a substantially better way to express a requirement than Form 1. For instance, in Form 2 the team is introduced to the target user, a Regional Director. Given this information, the User Interface can be tailored to the particular needs of a person with computer skills of a typical executive. Furthermore, Form 2 states that the Regional Director is really only interested in finding out about customers that have been inactive for more than 30 days. This information allows the team to develop a query system that has just enough functionality to meet the Customer Goal. Any additional functionality can be added to the query system later as Customer requirements dictate.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Given only the information in Form 1, a team can easily embark on development of an all inclusive query system that has features that are never used or valued by the Customer.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-8861753182165054027?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8861753182165054027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8861753182165054027'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/writing-effective-stories-for-scrum.html' title='Writing effective stories for a Scrum Sprint'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-4845722266670848347</id><published>2011-01-14T15:32:00.001-08:00</published><updated>2011-01-14T15:32:37.915-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Writing Unit Tests using Test Driven Development (TDD)</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Say a developer needs to write a new class called Person. A developer may proceed as follows:&lt;/span&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Create class Person and define all its public properties and methods with { throw new NotImplementedException; } as the body.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Create a Unit Test class called PersonTest and write [Tests] to exercise the public behavior and state of Person class.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Run the tests. All tests should fail.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Continue implementation of the Person class until all tests pass.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;When the above approach and naming strategy (classnameTest) is followed for Unit Tests, it is easier for developers to quickly locate, exercise and expand Unit Tests for a class when the functionality of that class is enhanced.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-4845722266670848347?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/4845722266670848347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/4845722266670848347'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/writing-unit-tests-using-test-driven.html' title='Writing Unit Tests using Test Driven Development (TDD)'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-8710684663138633538</id><published>2011-01-14T15:31:00.000-08:00</published><updated>2011-01-14T15:31:15.382-08:00</updated><title type='text'>Top 5 Tools for .NET Agile Development</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;In my opinion, the following are the top 5 tools for Agile Development in the .NET environment.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;NUnit - Helps write automated Unit Tests&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Automated Unit Tests are at the core of Agile development philosophy. NUnit Framework allows you to write automated Unit Tests for your .NET code. &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://www.nunit.org/index.php&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Rhino Mocks - Helps write more robust Unit Tests&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Think of Rhino Mocks as a supplement to NUnit. NUnit is very good at verifying the state of an object before and after execution. What RhinoMock adds is verification of object behavior (that is what methods are executed) during the test. The Rhino Mocks web site describes it as "A dynamic mock object framework for the .Net platform. It's purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing."&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://ayende.com/projects/rhino-mocks.aspx&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;NCover - Helps gauge if enough tests are written&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Simply put NCover monitors and reports the percentage code that is executed during a test run. The Code Coverage Percentage is a useful metric in itself. However, more importantly, NCover is really handy in discovering areas of codes that do not have Unit Tests written for them at all.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://www.ncover.com/&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;CruiseControl - Facilitates continuous integration&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;If you work in a team of more than one, CruiseControl is a must-have. CruiseControl serves the dual-purpose of a build/test machine as well as a continuous integration server. Equally important is the ability of CruiseControl to send build/test failure notifications to the developers. CCTray is a handy tool for developers to proactively monitor the CruiseControl server for build/test failures.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://cruisecontrol.sourceforge.net/&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://confluence.public.thoughtworks.org/display/CCNET/CCTray&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Visual Studio - Helps with refactoring&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Visual Studio provides a robust IDE for .NET development. The "Refactor" context menu options are particularly useful when refactoring code. For example, Refactor | Rename can be used to rename a variable or a method. Upon rename, Visual Studio will not only rename the variable or the method declaration but also all the references to the variable or the method. In addition to renaming, there are several other refactoring helpers available in Visual Studio.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;http://msdn.microsoft.com/en-us/visualc/aa700831.aspx&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-8710684663138633538?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8710684663138633538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/8710684663138633538'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/top-5-tools-for-net-agile-development.html' title='Top 5 Tools for .NET Agile Development'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-6710531178577783216</id><published>2011-01-14T15:29:00.000-08:00</published><updated>2011-01-14T15:29:14.433-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Engineering Practices'/><title type='text'>Agile Principles</title><content type='html'>&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;YAGNI - You aren't going to need it&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Don't anticipate features and try to adapt your design or code to the features that are not necessary to complete the stories at hand. The chances are that either the requirements will change over time or the features you anticipate are never really needed. Do the simplest thing that will work.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;DRY - Don't repeat yourself&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Factor out common code into helper classes, methods and components. This makes the testing effort more concise and helps track down bugs to a single place in code instead of several repeating code sections.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Minimize Code&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Minimize the amount of code you have to write to solve a problem. The less code there is, the lesser the chance of buggy code. Code Minimization goes beyond DRY in that you may opt to look at alternate design approaches that minimize the amount of code you have to write to begin with.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Write testable code&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Structure and implement your code so that it is easily testable. This mind set will naturally help you write code that is loosely coupled and minimizes interdependencies. The loose coupling is essential for testing a class or a component in isolation as is necessary when writing Unit Tests.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Write automated tests&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;By all means write automated Unit Tests. Better yet, take the Test Driven Development (TDD) route. That is, devise and write your tests before you start developing. TDD will greatly help in the design of the system in addition to the more obvious benefit of having a more complete set of automated tests. Having good automated unit tests allow us to refactor our code confidently.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Refactor, Refactor, Refactor&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Over the time, the code will naturally decay. You will see violations of DRY, Minimize Code and even YAGNI principles. It is imperative to take time to periodically refactor the code to ensure its maintainability over time.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri; font-size: large;"&gt;Integrate often - Fail fast&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;span style="font-family: Calibri;"&gt;Don't sit on pending changes. Check them in right away to find any incompatible changes. It is better to fail fast and correct the problem earlier in the cycle than to sit on a change and having to figure out why things don't work due to a change you made last week.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-6710531178577783216?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/6710531178577783216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/6710531178577783216'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2011/01/agile-principles.html' title='Agile Principles'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-3763721897297492375</id><published>2010-11-02T20:38:00.000-07:00</published><updated>2010-12-24T20:40:05.646-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enterprise Architecture'/><title type='text'>Coherent Architectures</title><content type='html'>In his paper, &lt;em&gt;Urban and Enterprise Architectures: A Cross-Disciplinary Look at Complexity&lt;/em&gt;, Roger Sessions talks about &lt;em&gt;Coherent&lt;/em&gt; architectures that are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Easier to implement&lt;/li&gt;&lt;li&gt;Easier to maintain&lt;/li&gt;&lt;li&gt;Easier to adapt&lt;/li&gt;&lt;li&gt;Are less complex&lt;/li&gt;&lt;/ul&gt;By gleaning into architecture of buildings, Sessions finds four attributes of architecture that make an architecture coherent.&amp;nbsp;He contends these attributes are equally applicable to Enterprise architecture.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Scale Range - There must be a range of architectural scales ranging from the very small to very large. For example, in buildings bricks make up the walls, walls make up the rooms, and rooms make up the building. Similarly, in an Enterprise architecture, there is a&amp;nbsp;scale range of&amp;nbsp;artifacts: data rows, tables, databases, programs, APIs, services, components, sub-systems, systems&lt;/li&gt;&lt;li&gt;Scale Hierarchy - There is an obvious&amp;nbsp; hierarchy of elements in a building. Buildings contain rooms, rooms contain walls, and walls contain bricks. Similarly, in Enterprise systems, raw data is contained in data rows, data rows are contained in tables, tables in databases, and databases are usually&amp;nbsp;accessed through a well-defined programmatic interface. In a Coherent architecture, this hierarchy is clearly decipherable.&lt;/li&gt;&lt;li&gt;Scale Connections - Couplings are between elements of like scale. For example, bricks couple with bricks to form a wall. Walls couple with other walls to form a room. In an enterprise system, for example, Web Services collaborate with other Web Services, but not with the underlying database of another system.&lt;/li&gt;&lt;li&gt;Scale Tightness - The higher up you go in the hierarchy, the &lt;em&gt;weaker&lt;/em&gt; the connection strength and there are &lt;em&gt;fewer&lt;/em&gt; connection points. For example, two autonomous systems are likely to communicate through an asynchronous message rather than a synchronous method invocation. Furthermore, connection points will be fewer between the two autonomous systems than between a data access layer of a subsystem and its database.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Reference: &lt;a href="http://www.objectwatch.com/whitepapers/SessionsSalingaros01.pdf"&gt;http://www.objectwatch.com/whitepapers/SessionsSalingaros01.pdf&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-3763721897297492375?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3763721897297492375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3763721897297492375'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/11/coherent-architectures_02.html' title='Coherent Architectures'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-3924443168094116735</id><published>2010-10-19T07:42:00.000-07:00</published><updated>2010-12-24T20:43:02.347-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enterprise Architecture'/><title type='text'>Enterprise Service Bus</title><content type='html'>Enterprise Service Bus (ESB) is an architecture style that provides plumbing for heterogeneous systems (legacy, client-server, SOA, message-oriented&amp;nbsp;middleware, MOM)&amp;nbsp;in an enterprise to collaborate in order to carry out the business processes. ESB utilizes the following primary constructs:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Messages/Events - ESB orchestrates routing of the messages to systems to&amp;nbsp;support stateful and stateless business processes.&amp;nbsp;ESB employs adapters to transform messages into a format suitable for the target system on the ESB&lt;/li&gt;&lt;li&gt;Standards-based messaging&amp;nbsp;- Supports complex Message Exchange Patterns (MEPs)&amp;nbsp;such as&amp;nbsp;Web Services, Messaging Middleware, Intelligent routing, Request/Response communication, One-way event notification&lt;/li&gt;&lt;li&gt;Service Registry - Provides a common directory of all services provided by systems in the Enterprise. Service Registry provides another layer of indirection to where these Services are physically present. The participants in ESB access all services through the Service Registry and are agnostic to physical addresses of these services&lt;/li&gt;&lt;/ul&gt;ESB attempts to reduce strong coupling between systems by providing for abstractions over underlying Services, APIs and Messaging Systems. ESB ensures delivery of messages:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;To the Right place (system)&lt;/li&gt;&lt;li&gt;At the right time (messages are delivered in correct sequence and within specified timeframes)&lt;/li&gt;&lt;li&gt;In the right format (ESB uses adapters to convert messages into appropriate formats for seamless consumption by target systems)&lt;/li&gt;&lt;/ul&gt;ESB goes beyond traditional Hub and Spoke architecture&amp;nbsp;prevalent in Enterprise Application Integration (EAI) by supporting a distributed architecture for message routing and transformation. All systems communicate in the same way with the ESB. ESB transforms and routes the message to the target consumer per the configuration. ESB also provides mechanisms for monitoring messages as they are move through the enterprise.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-3924443168094116735?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3924443168094116735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/3924443168094116735'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/10/enterprise-service-bus_19.html' title='Enterprise Service Bus'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-5619512828887791306</id><published>2010-09-07T15:01:00.000-07:00</published><updated>2011-01-14T14:46:33.602-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Computational Theory'/><title type='text'>P versus NP Problem</title><content type='html'>&lt;strong&gt;Is every algorithmic problem whose solution can be efficiently verified is efficiently computable?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Efficient Computation&lt;/h2&gt;Runs in time that is a fixed polynomial of the input size&lt;br /&gt;&lt;h2&gt;P - Polynomial Time&lt;/h2&gt;Class of problems with efficient solutions are known as P problems&lt;br /&gt;&lt;h2&gt;NP - Non-Deterministic Polynomial Time&lt;/h2&gt;Class of problems whose solution can be verified efficiently but&amp;nbsp;are difficult solve especially for large inputs (e.g. Traveling Salesman problem). That is, the problem cannot be solved in deterministic polynomial time (or in other words, efficient computation is not possible).&lt;br /&gt;&lt;h2&gt;NP-Complete&lt;/h2&gt;Given a set of&amp;nbsp;very hardest NP problems, find an efficient algorithm for one member in the set and then you&amp;nbsp;can certainly&amp;nbsp;found an efficient algorithm to solve all of the members of set&lt;br /&gt;&lt;h2&gt;P = NP&lt;/h2&gt;If this is proven to be true, we can find an efficient algorithm to solve any problem that has an efficiently verifiable solution. An efficient solution to any NP-complete problem would imply P=NP and hence an efficient solution to every NP-complete problem.&lt;br /&gt;&lt;h2&gt;P ≠ NP&lt;/h2&gt;Most computer scientists believe P ≠ NP. That is, not every solution-verifiable problem has an efficient solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-5619512828887791306?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5619512828887791306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/5619512828887791306'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/09/p-versus-np-problem_07.html' title='P versus NP Problem'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-1951393587269128589</id><published>2010-08-15T11:53:00.000-07:00</published><updated>2010-12-24T20:57:59.831-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>MapReduce</title><content type='html'>MapReduce&amp;nbsp;is used to&amp;nbsp;process&amp;nbsp;large data sets.&amp;nbsp;It comprises of two steps.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use a &lt;em&gt;Map&lt;/em&gt; function to break-down original (large) data sets into key/value pairs. These are&amp;nbsp;the &lt;em&gt;intermediate&lt;/em&gt; key/value pairs.&lt;/li&gt;&lt;li&gt;Use a &lt;em&gt;Reduce&lt;/em&gt; function combine the &lt;em&gt;intermediate&lt;/em&gt; key/value pairs to arrive at the final answer&lt;/li&gt;&lt;/ol&gt;MapReduce lends itself very well to parallel processing. Multiple clusters of compute nodes can independently work on different segments of data during both the &lt;em&gt;Map&lt;/em&gt; and &lt;em&gt;Reduce&lt;/em&gt; steps.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Example&lt;/h3&gt;&lt;h4&gt;Objective&lt;/h4&gt;Produce&amp;nbsp;a word count&amp;nbsp;from a large text corpus&lt;br /&gt;&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;Map Step&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;Iterate through all documents in the corpus. For each document:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Parse words&lt;/li&gt;&lt;li&gt;Create a&amp;nbsp;key (word) /value (count, 1)&amp;nbsp;pairs for each word found&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;h4&gt;Reduce Step&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;Sum together counts for all intermediate keys (words) to arrive at count for each word in the corpus&lt;/li&gt;&lt;/ul&gt;Hadoop MapReduce is a programming model and software framework for writing applications that rapidly process vast amounts of data in parallel on large clusters of compute nodes. &lt;br /&gt;See: &lt;a href="http://hadoop.apache.org/mapreduce/"&gt;http://hadoop.apache.org/mapreduce/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-1951393587269128589?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/1951393587269128589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/1951393587269128589'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/08/mapreduce_15.html' title='MapReduce'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-880706888615024194</id><published>2010-07-11T21:06:00.000-07:00</published><updated>2010-12-24T21:10:04.676-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>Observer Pattern</title><content type='html'>&lt;h3&gt;What&lt;/h3&gt;Let's say we have an object O whose state may change at anytime. There are other objects in our system that are interested in knowing when the state of object O changes. What we need is a way for object O to notify all the interested objects when its state changes. The Observer Pattern facilitates exactly that. It defines a one-to-many relationship between objects such that when one object changes its state, all dependent objects are notified. There are two kinds of the participants in the Observer Pattern:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The Subject also known as the Observable or the Publisher&lt;/li&gt;&lt;li&gt;The Observers also known as the Subscribers&lt;/li&gt;&lt;/ol&gt;The Observers register themselves with the Subject. The Subject notifies the registered Observers when a change in its state occurs. The order of notification to the registered Observers by the Subject is non-deterministic. That is, an Observer does not know whether it received the update notification from the Subject before or after other Observers.&lt;br /&gt;&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;&lt;h3&gt;Why &lt;/h3&gt;The biggest benefit of the Observer Pattern is the loose coupling between the Subject and the Observers. As long as the Observers implement an update notification interface supported by the Subject, they may register themselves for the update notifications. Conversely, the Observers know the Subject through Subject's well-defined interfaces. An Observer may unregister with the Subject if it is no longer interested in the notifications.&lt;br /&gt;&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;&lt;h3&gt;How&lt;/h3&gt;interface IObservableSubject&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; void RegisterObserver(IObserver observer);&lt;br /&gt;&amp;nbsp; void UnRegisterObserver(IObserver observer);&lt;br /&gt;&amp;nbsp; void NotifyObservers();&lt;br /&gt;}&lt;br /&gt;interface IObserver&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; void Update(IObservableSubject observableSubject);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A concrete ObservableSubject class implements the IObservableSubject interface along with its other core functionality. Internally, ObservableSubject object keeps a list of registered Observers and notifies them by calling their Update() method. Once notified of the update, the Observer objects may call query methods on the ObservableSubject object to retrieve the state they are interested in.&lt;br /&gt;&lt;br /&gt;A concrete Observer class implements the IObserver interface along with its other core functionality. The Observer class gets a reference to the concrete ObservableSubject class through its constructor. Typically in its constructor, the Observer object adds itself to the list of observers maintained by the ObservableSubject object by invoking the IObservableSubject::RegisterObserver() method.&lt;br /&gt;&lt;br /&gt;The implementation of Observer Pattern through interfaces is preferred over inheritance because an interface allows us to turn existing classes into Observers by simply implementing the IObserver interface. The same argument holds true when turning an existing class into an ObservableSubject by implementing the IObservableSubject interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-880706888615024194?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/880706888615024194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/880706888615024194'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/07/observer-pattern.html' title='Observer Pattern'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5437932071029458618.post-4700707754513471525</id><published>2010-06-04T21:11:00.000-07:00</published><updated>2010-12-24T21:16:19.814-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><title type='text'>Decorator Pattern</title><content type='html'>&lt;h3&gt;What&lt;/h3&gt;Decorator Pattern is used to extend existing functionality through composition instead of inheritance. Decorator Pattern can be used to intercept and modify the behavior of an existing class object. For example, say client code uses class object XYZ that implements an interface, ISomeInterface. Currently, the client code instantiates class object XYZ and uses it through its ISomeInterface. XYZ is almost perfect for us except a few behaviors we would like to tweak. We do not want to touch the code for XYZ because it has been tested and has been functioning well. Furthermore, we do not want to substantially change the client code that uses XYZ. Following the Decorator Pattern, we implement a new class KLM that implements ISomeInterface. KLM contains an instance of XYZ class object. KLM delegates the desired behavior to the contained XYZ class object but overrides undesired behavior where necessary. The only change that the client code needs to make is to instantiate KLM instead of XYZ and use it through its ISomeInterface as before.&lt;br /&gt;&lt;br /&gt;Decorator Pattern can be applied in a variety of modeling scenarios. Let's say we have an application that calculates the price of a car. There is the base price of the car and then there are additional costs for options such as sports suspension, all weather package and so on. The base price and the price of options may vary independent of each other. Further, the list of available options may change over time. Decorator Pattern is one way to model this kind of scenario.&lt;br /&gt;&lt;br /&gt;One way to visualize how the Decorator Pattern works is to visualize an onion. An onion has layers. Let's say the cost of each layer in the onion is different. The cost of the onion is equal to the cumulative cost of all layers. This visualization of the onion costing is not all that different from the car pricing scenario described above. We start with the base model for the car and decorate or wrap it with options. To calculate the total price of the car, we ask the outermost layer what is your cost. The outermost layer asks the layer next to it: what is your cost and adds to its own cost. The inner layer in turn asks the layer next to it what is your cost and adds to its own cost and so on.&lt;br /&gt;&lt;br /&gt;In the car pricing example, we can think of the base price and options as just car components. We wrap each component around another component until we have the car with the desired options. We ask the outermost car component to calculate its cost which in turn requests the cost from inner components to calculate the total cost of the car. &lt;br /&gt;&lt;br /&gt;The salient features of the Decorator Design Pattern are as follows:&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Common Super Type&lt;/h4&gt;All decorators used in a scenario derive from the same type or implement the same interface so that they can be used interchangeably. For the car pricing example, all car components implement the same interface in the code example below.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Composition&lt;/h4&gt;Each concrete implementation of a decorator contains a reference to the class object that it wraps. The object that a decorator wraps has the same super type as the decorator. For the car pricing example, the innermost decorator would not be wrapping or decorating anything because it is the base price for the car.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Delegation&lt;/h4&gt;Each decorator knows how to compute itself but delegates the computation of the decorator objects it wraps to the wrapped objects themselves. &lt;br /&gt;&lt;h3&gt;&lt;br /&gt;Why &lt;/h3&gt;The decorator objects are independent of each other except that they share a common super type or interface. We can leave existing class implementations untouched while extending their behavior through composition and delegation. A decorator does not care about how many other decorators there are in its family. At runtime, a client can create a custom scenario or configuration by composing desired decorators. When new decorators are needed, they are simply implemented and used by the client following the same pattern as before. This is a perfect example of extension of functionality without modification to existing code (decorators). In object oriented terms, this is an application of the open-closed principle. The design is open for extension but closed to modification of existing decorator classes. In the car pricing example above, if we used inheritance instead of composition, the open-closed principle would be much harder to follow. By using the Decorator Pattern, we can implement additional options (decorators) for the car without having to touch code for existing options (decorators).&lt;br /&gt;&lt;h3&gt;&lt;br /&gt;How&lt;/h3&gt;// Common interface all decorators in our car example implement&lt;br /&gt;interface ICarComponent&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; decimal Cost();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Implements common functionality for all Car Components&lt;br /&gt;abstract class CarComponent : ICarComponent&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; protected decimal m_ThisComponentCost;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; public CarComponent (decimal thisComponentCost)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_ThisComponentCost = thisComponentCost;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; public decimal Cost()&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // m_ThisComponentCost is set by the constructor&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; decimal cost = m_ThisComponentCost;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Cost of the car component this component decorates&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (m_CarComponent != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cost += m_CarComponent.Cost();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return cost;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Base Price for the car&lt;br /&gt;class AMWTurboBasePrice : CarComponent&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; public AMWTurboBasePrice ()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; : base (33000m)&amp;nbsp; // base price for the car&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_CarComponent = null;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Pricing for Sports suspension&lt;br /&gt;class SportsSuspension : CarComponent&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; public SportsSuspension (ICarComponent carComponent)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : base (4000m)&amp;nbsp; // price for sports suspension&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_CarComponent = carComponent;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;// What is the price of AMWTurbo with sports suspension&lt;br /&gt;ICarComponent basePrice = new AMWTurboBasePrice();&lt;br /&gt;ICarComponent basePriceWithSportsSuspension =&lt;br /&gt;&amp;nbsp; new SportsSuspension(basePrice);&lt;br /&gt;Console.WriteLine(&lt;br /&gt;&amp;nbsp;&amp;nbsp; String.Format("The cost of car is {0}", basePriceWithSportsSuspension.Cost());&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;// All Weather package just became available for our car&amp;nbsp;&amp;nbsp; &lt;br /&gt;// We implement a new decorator&lt;br /&gt;class AllWeatherPackage : CarComponent&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; public AllWeatherPackage (ICarComponent carComponent)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : base (2000)&amp;nbsp; // cost of all-weather package&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.m_CarComponent = carComponent;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;// What is the price of the AMWTurbo with&lt;br /&gt;// sports suspension AND all weather package&lt;br /&gt;ICarComponent basePriceWithSportsSuspensionAndAllWeatherPkg =&lt;br /&gt;&amp;nbsp;&amp;nbsp; new AllWeatherPackage(basePriceWithSportsSuspension);&lt;br /&gt;Console.WriteLine(&lt;br /&gt;&amp;nbsp;&amp;nbsp; String.Format("The cost of car is {0}", &lt;br /&gt;&amp;nbsp;&amp;nbsp; basePriceWithSportsSuspensionAndAllWeatherPkg.Cost());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5437932071029458618-4700707754513471525?l=sal-razzaq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/4700707754513471525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5437932071029458618/posts/default/4700707754513471525'/><link rel='alternate' type='text/html' href='http://sal-razzaq.blogspot.com/2010/06/decorator-pattern.html' title='Decorator Pattern'/><author><name>Sal Razzaq</name><uri>http://www.blogger.com/profile/09170402220701159195</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://4.bp.blogspot.com/-iayFRZwf-8A/T007TzwpREI/AAAAAAAAACo/pzbONq0E_NE/s220/Robin_small.jpg'/></author></entry></feed>
