Note - Loosely-Coupled Systems

The only constant thing about software during its development is change. Changes occur because: it is being created, we find latent errors in already developed parts, there are performance issues, or customers drive changes in the specifications or their interpretation. It is critically important that each change has a low probability of causing other conseqential changes. We build in robustness against change by partitioning a system into relatively small cohesive components that provide stable interfaces and object factories for the rest of the system to use. Part of the art of building robustness into systems is to partition into a structure that is suited to its application and each part is loosely coupled to the others.
It is common to think of a system as composed of a view, the application intelligence, and a data store. This is the basis for the three-tier model: Many of the Graphical User Interface (GUI) frameworks - WinForms, WPF, Asp.Net, gtk, etc - encourage you to tightly bind the view to the application processing and datastore. They do this through wizards, hundreds of examples, and a lot of documentation.

For simple applications that have a single view, simple logic, and one source of data, that's quick, easy, and perfectly reasonable implementation approach. But, many applications need:

For these more complex situations it becomes important to avoid tight bindings between layers of the system. We want to be able to add a new view that simply uses services defined by the application layer. We want to add additional business processing by simply adding a new service that uses existing services provided by the data layer. And we don't want the new business process to need to know the implementation details of the data service.

We achieve this by two simple but powerful ideas:

There are several patterns that arrange these ideas in slightly different ways: The Model View Controller, in its original form, used the controller primarily to dispatch event actions in the view to handlers in the model. In Frameworks like WinForms and WPF that dispatching happens in the view in a framework specific way. We, however, can simply delegate calls in the event handlers to the viewmodel using its service interfaces.

Conclusions:

Loosely-Coupled Systems depend on the implementation of two simple ideas:
  1. Require all communication between presentation, application, and data layers to use interfaces, creating the objects that implement the interfaces with object factories.
  2. Represent each layer with a model - View Model (VM), Application Model (AM), and Data Model (DM). The application model is the core of the system, using objects that are familiar to users, making this most complex part, easier to maintain. The view model handles the transformations between the states of business objects and data in the view. The data model abstracts away, for the business model, all of the storage details, e.g., connections strings, stored procedures, etc.
The trick, of course, is not to let the infrastructure of these models and dependency injection run away with the implementation. That's easier to say than to do. The (in)famous J2EE does all of these things and has the reputation of being big, bloated, and viciously hard to learn to use well.

The .Net community is trying to do these same things in a more piece-meal fashion (a good thing, I think) with the Entity Framework for Object Relational Modeling (ORM) and the Unity Framework to handle Dependency Injections.

I like to think that we can simplify this significantly. We will try some experiments in Projects #4 and #5 to see if we can indeed do that!