8 January 2019
By: Tomas Malmsten

Explicit Interface and Encapsulated Implementation patterns, DDD and the joy of patterns

It's funny how we encounter new things matching what we are not looking for. A little while back I was looking for a design pattern that would help me to solve an issue around data propagation. But I didn't find it. Instead I found two other patterns which can be used to simplify domain models (as in DDD domain models). Explicit Interface and Encapsulated Implementation. They are both defined in Pattern-Oriented Software Architecture Volume 4 - A Pattern Language for Distributed Computing (commonly referred to as the POSA 4 book).

Explicit Interface defines a well described interface which is exposed to clients. It's a foundation for a stable component interface. There are many similarities with Java interfaces actually, in that it only describes the contract but contains no implementation.

Encapsulated Implementation is the pattern commonly used to implement the Explicit Interface. It is never declared to the client, but used to separate the interface and the implementation.

Neither of the patterns are revolutionary, they are common practice. What is interesting is that someone have taken the time to define a good explanatory name to each. Making it so much more easy to explain what it is and to reason about it in conversations.

Also, they will be a great help when building a domain model. Sure, the Domain Object should have all the operation on it, as should the Aggregate and Value Object. But it doesn't have to pack the implementation as well. The pattern names help to communicate this to developers in a succinct way.

So, no, not a ground breaking discovery. But I love to find good established names for things I often refer to. Especially when I also need to talk to other about them. It's so much easier to express an idea using an established pattern name than to have to describe the details of the pattern every time.

There are many more patterns in the POSA series. There are five books in all. So if you haven't read them I'd highly recommend it.

Tags: DDD Design Patterns