SOLID Principles in JavaScript
Which SOLID principle suggests that we should depend on abstractions rather than concretions?
// Before:
class PaymentProcessor {
constructor() {
this.stripe = new StripePayment();
}
processPayment(amount) {
return this.stripe.charge(amount);
}
}
// After:
class PaymentProcessor {
constructor(paymentProvider) {
this.paymentProvider = paymentProvider;
}
processPayment(amount) {
return this.paymentProvider.processPayment(amount);
}
}