concept Demeter in category asp.net

appears as: Demeter
ASP.NET MVC in Action with MvcContrib, NHibernate, and More

This is an excerpt from Manning's book ASP.NET MVC in Action with MvcContrib, NHibernate, and More.

As with everything in the ASP.NET MVC Framework, there is very little the developer must do to create custom functionality. In the case of the controller, the only—I will say it again—the only requirement is that the class implement the IController interface . This interface only requires that you implement a single method: Execute. How you handle the request is entirely up to you. In the controller in listing 1.7, we’re intentionally violating all principles of sensible programming as well as the Law of Demeter in order to get the message “Hello World” written out to the screen as quickly as possible. In this case, I’ve chosen not to make any use of a view. Rather, I’m formulating incomplete HTML markup and directing it to the response stream. We’ll run the sample and note the output in figure 1.6. In the code solution that comes with the book, you can find HelloWorld1ControllerTester that illustrates how you’d unit test a simple controller like this.

Quickly we can see that using Response.Write() from our code is a cumbersome way to render content for an AJAX request when the logic is nontrivial. As the number and size of the AJAX request/responses increase, Response.Write() becomes very difficult to maintain. The Law of Demeter violation also increases the difficulty of unit testing this handler class. We’d like to use the templating power of ASPX, without using full HTML documents.