Ayende @ Rahien

Refunds available at head office

Limit your abstractions: So what is the whole big deal about?

When I started out, I pointed out that I truly dislike this type of architecture:

image

And I said that I much rather an architecture that has a far more limited set of abstractions, and I gave this example:

  1. Controllers
  2. Views
  3. Entities
  4. Commands
  5. Tasks
  6. Events
  7. Queries

That is all nice in theory, but let us talk in practice, shall we? How do we actually write code that actually uses this model?

Let us show some code that uses this type of code, this type, this is from the C# port of the same codebase, available here.

public class CargoAdminController : BaseController
{
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Register(
      [ModelBinder(typeof (RegistrationCommandBinder))] RegistrationCommand registrationCommand)
  {
      DateTime arrivalDeadlineDateTime = DateTime.ParseExact(registrationCommand.ArrivalDeadline, RegisterDateFormat,
                                                             CultureInfo.InvariantCulture);

      string trackingId = BookingServiceFacade.BookNewCargo(
          registrationCommand.OriginUnlocode, registrationCommand.DestinationUnlocode, arrivalDeadlineDateTime
          );

      return RedirectToAction(ShowActionName, new RouteValueDictionary(new {trackingId}));
  }
}

Does this looks good to you? Here is what is actually going on here.

image

You can click on this link look at what is going in here (and I removed some stuff for clarity’s sake.

This stuff is complex, more to the point, it doesn’t read naturally, it is hard to make a change without modifying a lot of code. This is scary.

We have a lot of abstractions here, services and repositories and facades and what not. (Mind, each of those thing is an independent abstraction, not a common one.)

In my next post, I’ll show how to refactor this to a much saner model.

Comments

awl
02/16/2012 03:48 PM by
awl

FYI When I click on the diagram, I only see a small copy. Too small to read.

Ayende Rahien
02/16/2012 04:38 PM by
Ayende Rahien

Image link has been fixed.

Ayende Rahien
02/16/2012 04:42 PM by
Ayende Rahien

http://ayende-temp.s3.amazonaws.com/Blog-posts-154177-Diagram.pdf

Neil Mosafi
02/16/2012 04:43 PM by
Neil Mosafi

Ahh lol me being a dumbass

RichB
02/16/2012 04:43 PM by
RichB

When I click the picture, it's the same size...

Mads Laumann
02/16/2012 06:46 PM by
Mads Laumann

Uhhh, a cliffhanger :)

Looking forward to see the refactored version.

Mohamed RAHIM
02/16/2012 06:53 PM by
Mohamed RAHIM

Is this a REVIEW (Rebuttal) of the DDD Abstractions (Introduced By Eric Evans)? Or only a REVIEW of the Cargo specific DDD Sample?

dotnetchris
02/16/2012 07:27 PM by
dotnetchris

The code at the controller level looks pretty reasonable.... But that call graph is fucking absurd.

Falhar
02/16/2012 07:41 PM by
Falhar

I think most of this code is domain code. And this code is unrelated to service or facade itself. Only thing I see, that can simplyfy it is to divide method in BookingService into smaller parts.

Dan
02/16/2012 10:53 PM by
Dan

What program did you use to generate that sequence diagram?

Harry Steinhilber
02/17/2012 12:42 AM by
Harry Steinhilber

@Dan - it looks like the sequence diagram generated by Visual Studio Ultimate (right click on a method and select Generate Sequence Diagram).

Arcan
02/17/2012 01:03 PM by
Arcan

I have been reading your apporoach since a while now also i reviewed effectus source code but im always wondering can this apporoach be used with webforms and how can you do it (the problem with the life cycle no controllers as boundary) ? i hope i will get an answer thank you in advance

Ayende Rahien
02/17/2012 09:39 PM by
Ayende Rahien

Arcan, You can use similar approach, sure. You can look at how Rhino Igloo was implemented for some ideas on structuring things in WebForms world.

Arcan
02/17/2012 09:49 PM by
Arcan

Thank you i have been thinking to use webforms mvp specially the message bus and publish subscribe that it use to communicate between different presenters or may be i will adapt it to fit my needs :) thank you again

Comments have been closed on this topic.