this post was submitted on 10 Mar 2024
15 points (85.7% liked)

Programming

17479 readers
259 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 8 months ago (1 children)

I'd call this pattern a service factory approach given what's being shown. Usually dependency injection hides the service specifics from the consumer. I'd say I want my class to have an iterator and some framework thing would assign a class to my constructor that fulfills that interface. This may seem like a pedantic point but at the level of distinguishing something as a dependency injection we're getting down to the really fine grained distinctions... pretty much everything needs to do sort of the same thing (build services into other services) and the different approaches are really just about how we specifically do that.

[–] Lmaydev 3 points 8 months ago

Dependency injection is the actual act of allowing dependencies to be injected. Which this does.

Creating a constructor that takes dependencies is DI.

Using something to inject them automatically is more inversion of control.

[–] KindaABigDyl 1 points 8 months ago (1 children)

I didn't know Go had interfaces. Neat

[–] [email protected] 3 points 8 months ago

It does and they're kinda weird (if you're used to more like Java-style interfaces). It flips the dependency between the interface and implementor on its head. Worth looking it up, it's interesting.