go-structure-examples icon indicating copy to clipboard operation
go-structure-examples copied to clipboard

Why are service interfaces not defined near the consumer (rest-handler)?

Open wilfreddesert opened this issue 1 year ago • 2 comments

Hi! I am referring to the hexagonal architecture example. It's a well-known idiom in Go that a consumer defines the interfaces it needs. In this particular case, why not define the three service interfaces in the http package?

Thanks!

wilfreddesert avatar Aug 17 '23 20:08 wilfreddesert

I guess defining the interface in a more central place makes sense if you anticipate more than one consumer. Like say supporting two transports HTTP & gRPC.

godwhoa avatar Aug 18 '23 08:08 godwhoa

Thanks for answering. I don't really understand what it simplifies though. If I understand correctly, the idea is to avoid copying the same interface in all so-called "driver adapters". But a little copying never killed nobody, quoting the Go proverbs.

Also, I'm not sure what is the benefit of returning the Service interface instead of a concrete implementation struct.

wilfreddesert avatar Aug 18 '23 09:08 wilfreddesert