Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dependency injection to dependency inversion #683

Open
ghost opened this issue Sep 9, 2023 · 0 comments
Open

Change dependency injection to dependency inversion #683

ghost opened this issue Sep 9, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 9, 2023

On page 6,

We’ve extracted the charging logic into the Payments interface—in essence employing dependency injection.

I believe dependency inversion would be more a accurate term here.

You improved the domain modelling of the program by no longer having a credit card charge itself (no idea why it was doing this in the first place) and then having a payment processor doing it instead. You then used a trait for the payment processor instead of a concrete implementation for the sake of dependency inversion, which you achieve through dependency injection...however you don't have any more dependency injection than you had before and you could've made CreditCard a trait as well with a concrete SimulatedCreditCard class and achieved the same result. So adding the payment processor didn't change anything except model your domain better and the dependency injection that you already had simply allowed you to achieve dependency inversion by depending on a trait rather than a concrete implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants