* BAEL-6830 example changed based on editor review comments

* BAEL-6830 example changed based on editor review comments

* BAEL-6830 example changed based on editor review comments
This commit is contained in:
Shahul Basha
2023-09-10 11:45:10 -04:00
committed by GitHub
parent fa5eb584ed
commit f3069c6ebc
6 changed files with 104 additions and 91 deletions
@@ -0,0 +1,22 @@
package com.baeldung.constructor;
public class PaymentProcessor {
private final PaymentService paymentService;
public PaymentProcessor(PaymentService paymentService) {
this.paymentService = paymentService;
}
public PaymentProcessor() {
this.paymentService = new PaymentService();
}
public PaymentProcessor(String paymentMode) {
this.paymentService = new PaymentService(paymentMode);
}
public String processPayment(){
return paymentService.processPayment();
}
}
@@ -0,0 +1,19 @@
package com.baeldung.constructor;
public class PaymentService {
private final String paymentMode;
public PaymentService(String paymentMode) {
this.paymentMode = paymentMode;
}
public PaymentService() {
this.paymentMode = "Cash";
}
public String processPayment(){
// simulate processing payment and returns the payment mode
return this.paymentMode;
}
}
@@ -1,18 +0,0 @@
package com.baeldung.constructor;
public class User {
private final UserService userService;
public User() {
this.userService = new UserService();
}
public User(String userName) {
this.userService = new UserService(userName);
}
public String getUserName(){
return userService.getUserName();
}
}
@@ -1,18 +0,0 @@
package com.baeldung.constructor;
public class UserService {
private final String userName;
public UserService(String userName) {
this.userName = userName;
}
public UserService() {
this.userName = "Unknown";
}
public String getUserName(){
return this.userName;
}
}