I’ve got a problem designing architecture for an application combining Domain Driven Desing principles with REST. The biggest problem for me here is that the Domain is just interfaces specification and response entities. Of course I can change this common layer as I please, but for now that’s the idea. I need this common layer because I want to be able to plug one of many implementations to the domain-based interface.
So here it comes:
- There are different business process engines
- In order to have a common API for all of them I need to wrap them in my wrapper classes which will implement my interfaces
- I expect from my wrappers to have good encapsulation (as DDD shows it - not to expose their internal specifics)
- I also expect to be able to expose my domain objects through REST and here comes the biggest problem:
Option 1: I could combine encapsulation with REST with classical objects (just have public methods exposing behaviours and private fields annotated by @JsonProperty), but I need interfaces (or I could use abstract classes), and you can’t have private inherited fields there...
Option 2: I could use public getters annotated by @JsonProperty, but that would break encapsulation
Option 3: So what I thought would be good here, at least from encapsulation point is creating immutable value objects that will be implemented (if you can say that set of public fields is an implementation) in the common layer, and will be use as input and output for specific methods called on domain objects. Is it a good option? I have no idea… It just seems to work well and don’t brake encapsulation principle
I think it basically explains my problem. What I think would be good for the REST API is using Restlet Objects, but it’s a problem for me to wrap my mind around Restlet Objects, that are in fact interfaces implemented by different implementation classes…
I’m attaching some basic architecture diagram, maybe It’ll help you understanding my problem: