Functional Patterns in Domain-Driven Design
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.
How Can We Use Our Creative Power and Technological Opportunity to Address the Challenges of the 21st Century?
Gyorgyi Galik Feb 26, 2015