the book "Clean Architecture" said:
When using dynamically typed languages like Ruby and Python ... dependency inversion does not require either the declaration or the inheritance of interfaces.
but I don't quite understand it, the book didn't provide any example
my understanding of the DIP is that if ClassA depends on ClassB violating the DIP, we can introduce an InterfaceC, then we get something like
ClassA ---> InterfaceC <--- ClassB
I've also looked at some examples on the internet, like this one that attempts dependency injection between PurchaseHandler
and PayPal
, https://duncan-mcardle.medium.com/solid-principle-5-dependency-inversion-javascript-7b054685f7cb
class PurchaseHandler {
processPayment(paymentDetails, amount) {
const paymentSuccess = PaymentHandler.requestPayment(
paymentDetails,
amount
);
if (paymentSuccess) {
// Do something
return true;
}
// Do something
return false;
}
}
class PaymentHandler {
requestPayment(paymentDetails, amount) {
// Complicated, PayPal specific logic goes here
return PayPal.requestPayment(paymentDetails, amount);
}
}
However, it seems to simply add a layer between them, resulting in this dependency graph:
PurchaseHandler ---> PaymentHandler ---> PayPal
no inversion is happening here...