Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,953 | Comments: 44,409

filter by tags archive

Limit your abstractionsSo 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.

More posts in "Limit your abstractions" series:

  1. (22 Feb 2012) And how do you handle testing?
  2. (21 Feb 2012) The key is in the infrastructure…
  3. (20 Feb 2012) Refactoring toward reduced abstractions
  4. (16 Feb 2012) So what is the whole big deal about?
  5. (15 Feb 2012) All cookies looks the same to the cookie cutter
  6. (14 Feb 2012) Commands vs. Tasks, did you forget the workflow?
  7. (13 Feb 2012) You only get six to a dozen in the entire app
  8. (10 Feb 2012) Application Events–event processing and RX
  9. (09 Feb 2012) Application Events–Proposed Solution #2–Cohesion
  10. (07 Feb 2012) Application Events–Proposed Solution #1
  11. (06 Feb 2012) Application Events–what about change?
  12. (03 Feb 2012) Application Events–the wrong way
  13. (02 Feb 2012) Analyzing a DDD application

Comments

awl
awl

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

Ayende Rahien

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

Neil Mosafi

Ahh lol me being a dumbass

RichB

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

Mads Laumann

Uhhh, a cliffhanger :)

Looking forward to see the refactored version.

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

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

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
Dan

What program did you use to generate that sequence diagram?

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

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

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

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

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
  2. Special Offer (2):
    27 May 2015 - 29% discount for all our products
  3. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  4. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  5. Interview question (2):
    30 Mar 2015 - fix the index
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats