BAEL-6830 (#14742)
* 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:
+22
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user