外观模式,改造后
This commit is contained in:
@@ -13,23 +13,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class GiftExchangeService {
|
||||
|
||||
private PointPaymentService pointPaymentService;
|
||||
private PointPaymentService pointPaymentService = new PointPaymentService();
|
||||
|
||||
private QualifyService qualifyService;
|
||||
private QualifyService qualifyService = new QualifyService();
|
||||
|
||||
private ShippingService shippingService;
|
||||
|
||||
public void setPointPaymentService(PointPaymentService pointPaymentService) {
|
||||
this.pointPaymentService = pointPaymentService;
|
||||
}
|
||||
|
||||
public void setQualifyService(QualifyService qualifyService) {
|
||||
this.qualifyService = qualifyService;
|
||||
}
|
||||
|
||||
public void setShippingService(ShippingService shippingService) {
|
||||
this.shippingService = shippingService;
|
||||
}
|
||||
private ShippingService shippingService = new ShippingService();
|
||||
|
||||
/**
|
||||
* 系统交互逻辑
|
||||
|
||||
@@ -15,9 +15,7 @@ class GiftExchangeServiceTest {
|
||||
PointGift pointGift = new PointGift("手环");
|
||||
// 注入服务
|
||||
GiftExchangeService exchangeService = new GiftExchangeService();
|
||||
exchangeService.setPointPaymentService(new PointPaymentService());
|
||||
exchangeService.setQualifyService(new QualifyService());
|
||||
exchangeService.setShippingService(new ShippingService());
|
||||
|
||||
// 兑换
|
||||
exchangeService.giftExchange(pointGift);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user