Wednesday, February 13, 2008

Foundations of Programming, by Karl Seguin

Foundations of Programming - an excellent series of articles about better programming algorithms, practices, and tools from .NET programmer's perspective. Written by Karl Seguin, a Microsoft ASP.NET MVP.

Foundations of Programming - ZIP/PDF
Part 1 - Introduction
Part 2 - Domain Domain Domain
Part 3 - Persistence
Part 4 - Dependency Injection
Part 5 – Unit Testing
Part 6 - NHibernate
Part 7 - ActiveRecord

Very interesting and helpful information about Object-Relational Mapping (ORM) concept and existing tools; about Dependency Injection (DI) concept and existing tools. This stuff is really important, because it shows what is a good way to separate application layers (UI, Business == Domain, Data Access). What Thiru Thangarathinam showed in his "N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005" article seems to be far from optimal, because in his example there is a tight coupling between layers. One layer explicitly created an object of another layer, explicitly calls methods of another layers, everything is tied to TableAdapters, etc. (It looks like there are a lot of programmers who are trying to write articles just after they learned a new technique, without real understanding of design issues.)

Karl shows, among other things, how to use Interfaces to decouple layers and particular database providers.

There are different aspects described in that article. Unit Testing is an interesting technology, but I don't think we will use it right away. NHibernate is a powerful Object-Relation Mapper (ORM) which sits between database and business layer (Domain layer) and maps relational data to your objects in a standard and flexible way, allowing to decouple database from domain. MS is releasing Entity Framework (EF) as a part of Astoria. It's a MS way of doing ORM. So, we might look at it as well.

But there is one part in that article talking about Dependency Injection and using StructureMap tool. It seems to be most relevant for my development. It basically allows to use stubs (mocks) for pieces of code which are not yet developed. So, when you need to work on domain layer (business classes), but don't have data-source layer (ORM) yet, you can substitute calls to data-source layer by calls to some mock classes. To do it you only need to change one line in StructureMap's XML configuration file.
It also makes it easier to switch from one implementation of data-source layer to another if necessary, without changing a single line of code in domain (business) layer!

The Code Wiki by Karl Seguin - a website designed to help coders become better developers. At the core of this websites sits The Code Wiki application, built, from the ground up, as a learning tool.
The Code Wiki book (PDF) - this book is about introducing and exploring alternatives to how you design, write and test your code on a day to day basis.