On Tue, Sep 26, 2023 at 6:18 AM Jerry Londergaard
<jlonderga...@gmail.com> wrote:
>
>
> Do I need to be re-defining this interface everywhere? I guess
> an alternative would be to just re-use the `C.DoThinger`, but I feel like 
> this doesn't seem right as now A is directly importing C, which seems to 
> 'break' the abstraction provided by B:


It looks like you can at least get rid of the definition in package A.
It already has a dependency on B.

If an interface is common enough, you can define it in a common
package imported by other packages. A common pattern I use is to
define interfaces and models at the package root level and then create
additional packages under it for the actual implementation(s). That
is,

package C

type Something interface {...}

type Model struct {...}

Then, the package C/D would have the implementation of the package.

But at the end of the day, it is subjective. There is no single right answer.





>
> ----------------------------------------------
> package A
> import (
>     "B",
>     "C"
> )
>
> func Run(dt C.DoThinger) {
>     B.Call(dt)
> }
> ```
>
> We could obviously define the interface elsewhere in one place, and have A, B 
> and C share use of it. This doesn't seem like the end of the world, as any of 
> the consumers of that interface can define a new local interface if the 
> shared one becomes unsuitable for them.
>
> My current implementation (the example given), is to reduce coupling between 
> packages. Should I be thinking about this differently? Should I be concerned 
> that I'm not adhering to DRY?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/a0436c1c-b24b-4c64-a4bc-12993c25c360n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2RqpgBVfF%3DrboFr0j6gw2%3Dh5BWkbSGxm0nvjZvtX1FpwT-Q%40mail.gmail.com.

Reply via email to