Functional Patterns in Domain-Driven Design

by Jan Stenberg on May 31, 2014 |

Domain-Driven Design (DDD) does a great job in encouraging developers to create a domain model and an ubiquitous language, but trying to implement DDD concepts using object orientation principles with state and behaviour often gives you a muddled mutable model, Debasish Ghosh states in a blog post about functional patterns in domain modelling.

Debasish, a senior member of ACM and author of DSLs in Action, argues that a model may be rich in the sense that all concepts related to a particular domain abstraction are located in one class but that this also makes the class more fragile with a local instead of a global focus, thus when composing all abstractions in a domain it may become too polluted with code just needed to resolve the impedance mismatch between class boundaries.

In his arguing he refers to Dean Wampler who recently argued that functional programming principles can help improve in domain driven design. Dean claims that "Models should be anaemic", encouraging a practice with domain objects having only state and moving behaviours into standalone functions.

Another statement Debaish argues against is that bundling state and behaviour in a class increases encapsulation, instead he believes that building domain behaviours as standalone functions leads to a better modularization and realization of the domain model according to the principles of DDD. All domain behaviours are then modelled as functions in a module representing the aggregate.

As an example he continues from earlier blog posts where he implemented the Specification and Aggregate patterns in DDD using functional programming principles, now using functional patterns and functions as building blocks to build behaviours that model the ubiquitous language of the domain. Debaish claims that one principle in DDD is to lift the domain model vocabulary into your implementation so that the functionality becomes obvious during the whole system lifecycle.

Dean Wampler also did a presentation on a similar topic at the React conference in April talking about reactive design and language paradigms.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.