Search posts, tags, users, and pages
Learn about the SOLID principles of software development and how to implement them in Spring Boot with code examples and detailed explanations.
Amr Khaled
@amrkh97 · Cairo, Egypt
An Enthusiastic Software Engineer
An experienced Software engineer with extensive knowledge in Fullstack development ( Java - Angular 8+ ) and Data Science.
Markdown supported · ⌘↵ to post
JS Rammohan
First of all, thanks for the detailed explanation about solid principles usage. I have a question about how to initialize runtime object of PaypalPaymentService for Rest Controller in DIP example.
Thank you so much, and sorry for the very late reply.
You can initialize it in multiple ways:
1- Constructor injection:
private final PaymentService creditCardPaymentService; private final PaymentService payPalPaymentService;
@Autowired public PaymentController(CreditCardPaymentService creditCardPaymentService, PayPalPaymentService payPalPaymentService) { this.creditCardPaymentService = creditCardPaymentService; this.payPalPaymentService = payPalPaymentService; }
2- With qualifiers:
@Qualifier("payPalPaymentService") public class PayPalPaymentService extends PaymentService {
and then in your controller or other service:
@Autowired public PaymentController(@Qualifier("creditCardPaymentService") PaymentService creditCardPaymentService, @Qualifier("payPalPaymentService") PaymentService payPalPaymentService) { this.creditCardPaymentService = creditCardPaymentService; this.payPalPaymentService = payPalPaymentService; }
JS Rammohan
First of all, thanks for the detailed explanation about solid principles usage. I have a question about how to initialize runtime object of PaypalPaymentService for Rest Controller in DIP example.