学习路径:https://coding.imooc.com/class/270.html
外观模式 应用场景:当业务需要调用多个子系统的时候,不单独调用子系统,将用到的子系统封装成一个类给业务层。 如:ShoppingService + TakeExerciseService + WatchMovieService ==> LeisureTimeService LeisureTime就是购物 锻炼 看电影的一个外观,外部不需要了解子系统都干了什么。 // 传统方法:在应用层写好步骤,依次调用子系统 //校验用户有没有资格换礼品 : giftExchangeService.setQualifyService(new QualifyService()); //用户消费积分换礼品: giftExchangeService.setPointPaymentService(new PointPaymentService()); //用户的礼品的物流信息: giftExchangeService.setShippingService(new ShippingService()); // 外观模式,只提供一个外观给外部调用,隐藏细节 // 指定要一个T-shirt的礼品 PointGift pointGift = new PointGift("T-shirt"); GiftExchangeService giftExchangeService = new GiftExchangeService(); giftExchangeService.giftExchange(pointGift);