DDD infected

July 11th, 2007

Just caught myself writing this snippet just now:

public class SessionCart
	private List<CartLine> lines = new List<CartLine>();

	public CartLine AddLine(ProductVariation productVariation)
		CartLine line = GetLineByProductVariation(productVariation);
		if (line != null)
			line = new CartLine(...);

		return line;


Where IncrementQuantity is

public void IncrementQuantity()

…and said to myself “Ok, I’m Domain-Driven Design infected”

7 Responses to “DDD infected”

AsbjornM Says:

So, Why didn’t you do:

if (!line.IsNull)

As well? :)

AsbjornM Says:

Oh, sorry, missed out bad.. big bummer.. sigh..

Markus Zywitza Says:

You should really consider overloading the ++ and — operators for CartLine ;-)

Then you are not only DDD but also technically state of the art… :-)))

OTOH you could also think about creating a DSL for managing carts >:-]


puzanov Says:

Seems that you more “writing self-documented code” infected than DDD. But that’s really good practice, I think!

hammett Says:

There’s an overlap there, IMHO. DDD is about building a Domain that reveals the intention, making somewhat obscure logics clear.

Janne Majaranta Says:

While in first iteration the IncrementQuantity method with just quantity++ might look like too chatty, it is nice to have an explicit method for it when the customer requires some business rules related to the quantity calculation of Cart Lines, which could be then injected ( or rather dispatched ) to/in the IncrementQuantity method (
like the Product with the attribute A can only be ordered in
sets of 10 pce., etc..).

I have found it to be a very nice effect of DDD that when
designing the public API very explicit and intention revealing,
it sometimes “automagically” creates “customer specification extension points” in the right places so that the inner workings
can be refactored with minimal effort when the customer specs
change or more features are requested.

mawi Says:

Hey Hammett,

I don’t think the line qualifies as being “especially” DDD. It is actually “just” OOP; the message sending bit, right? As Thomas/Hunt say, “Tell the other guy”.

Still, most devs still do alot of this:


Which is decidedly procedural – whereas this is OOP:



Leave a Reply