| ▲ | jbreckmckye 2 days ago | |
Rather than defining all these one-method interfaces, why not specify a function type? Instead of
You could have
Seems less bulky than an interface, more concise to mock too.It's more effort when you need to "promote" the port / input type to a full interface, but I think that's a reasonable tradeoff to avoid callers of your function constantly creating structs just to hang methods off | ||
| ▲ | lenkite a day ago | parent [-] | |
With Go had something similar to Java's `@FunctionalInterface` annotation, where a functions signature (parameters and return type) is implicitly matched against the single abstract method of a functional interface and where existing matching methods of any object can also be used as implementations of functional interfaces. | ||