#Apropiate way to enforce interface implementation

4 messages · Page 1 of 1 (latest)

weak prairie
#

Hi! First time posting something here. Im working on a system that works with multiple payment providers, in summary all of them should be capable of the same basic operations (refunds, list recent transactions, etc...) and I want to enforce the implementation of those functionalities using structs, because I work with a team and I want to leave as little room as possible to make this kind of mistakes.

My current idea is having an interface with the methods required for certain feature to work, like "RefundService", and then implement its methods on an specific payment provider like "SumUpService". The thing I am doing and feel it is weird it is the "type check" in the SumUpService, var _ RefundService[models.SumUpRefund] = &SumUpService{} as you can see in the screenshot it shows the error message I want, telling me some methods are missing implementation.

I want to know if there is a more idiomatic way of achieving the same or if you think I am designing the system wrong and should take a different approach.

Note: This is an iteration over an MVP that already worked, so we are trying to build a more robust and scalable system over the original idea, so just saying "You should just use any and then do type checks everywhere" is not an option I would like to implement..

cobalt fulcrum
rare pollen
#

I mean you can also just use the type/try to pass it in and it'll error out there

#

and/or have tests that would also fail to compile