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:
And I said that I much rather an architecture that has a far more limited set of abstractions, and I gave this example:
- Controllers
- Views
- Entities
- Commands
- Tasks
- Events
- 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.
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:
- (22 Feb 2012) And how do you handle testing?
- (21 Feb 2012) The key is in the infrastructure…
- (20 Feb 2012) Refactoring toward reduced abstractions
- (16 Feb 2012) So what is the whole big deal about?
- (15 Feb 2012) All cookies looks the same to the cookie cutter
- (14 Feb 2012) Commands vs. Tasks, did you forget the workflow?
- (13 Feb 2012) You only get six to a dozen in the entire app
- (10 Feb 2012) Application Events–event processing and RX
- (09 Feb 2012) Application Events–Proposed Solution #2–Cohesion
- (07 Feb 2012) Application Events–Proposed Solution #1
- (06 Feb 2012) Application Events–what about change?
- (03 Feb 2012) Application Events–the wrong way
- (02 Feb 2012) Analyzing a DDD application
Comments
FYI When I click on the diagram, I only see a small copy. Too small to read.
Post a larger image please!
Image link has been fixed.
It hasn't
Niel, Look at the link.
http://ayende-temp.s3.amazonaws.com/Blog-posts-154177-Diagram.pdf
Ahh lol me being a dumbass
When I click the picture, it's the same size...
Uhhh, a cliffhanger :)
Looking forward to see the refactored version.
Is this a REVIEW (Rebuttal) of the DDD Abstractions (Introduced By Eric Evans)? Or only a REVIEW of the Cargo specific DDD Sample?
The code at the controller level looks pretty reasonable.... But that call graph is fucking absurd.
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.
What program did you use to generate that sequence diagram?
@Dan - it looks like the sequence diagram generated by Visual Studio Ultimate (right click on a method and select Generate Sequence Diagram).
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
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.
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