OdeToCode IC Logo

Horizontal and Vertical Coupling

Saturday, March 11, 2006

One aspect of the default ASP.NET 2.0 project model I really like is how the code-beside file and the declarative markup file compile at the same time.

The compilation model produces a comfortable coupling between the declarative markup and the class in the code-beside file. This is ‘vertical coupling’. The ASP.NET runtime can generate strongly typed properties for the code-beside class via the magic of partial classes.

Web Application Projects for Visual Studio 2005 delivers the ASP.NET 1.1 code-behind model for ASP.NET 2.0. Many applications will have an easier migration path to 2.0 with WAP.

One problem I watch for with the old compilation model is unwanted coupling between types in the code-behind files. This is ‘horizontal coupling’. Instead of using a layer of indirection, like an interface, base class, delegate, or event, types in the code-behind files can reference each other directly and produce brittle code.

Horizontal coupling is bad. Vertical coupling is good.

Keyvan Nayyeri Sunday, March 12, 2006
Thank you very much Scott for pointing to this helpful tip ;)
Comments are closed.