Search code examples
hexagonal-architecture

Ports and Adapters – Should interfaces specify arguments as domain objects?


When specifying a port, should that interface define it's arguments in terms of domain objects e.g.

interface AddUser {
  firstName: FirstName
  lastName: LastName
}

and simple or "plain" types e.g.

interface AddUser {
  firstName: string
  lastName: string
}

My first thought would be that defining them as domain objects means that the implementing adapter will have to change should the domain model change. But the implementing adapter would have to change regardless of how the interface's arguments are defined, even if the arguments were as "plain types", no? Using "plain types" just means I'll have to parse the incoming arguments to domain types.

However, using domain types means I know the data is in the right form when I pass it to the port. It also doesn't violate the idea that dependencies should go inward.


Solution

  • Ports and adapters does not say anything about how to define the API. It is up to you whether you want the application to expose domain objects to the outside world or not.