-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
25 lines (23 loc) · 922 Bytes
/
Client.java
File metadata and controls
25 lines (23 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package designpattern.behavioral_pattern.strategy.v2;
import designpattern.util.XMLUtil;
public class Client {
public static void main(String args[]) {
MovieTicket mt = new MovieTicket();
double originalPrice = 60.0;
double currentPrice;
mt.setPrice(originalPrice);
System.out.println("原始价为:" + originalPrice);
System.out.println("---------------------------------");
Discount discount;
discount = (Discount) XMLUtil.getBean("designpattern.behavioral_pattern.strategy.v2.Discount"); //读取配置文件并反射生成具体折扣对象
mt.setDiscount(discount); //注入折扣对象
currentPrice = mt.getPrice();
System.out.println("折后价为:" + currentPrice);
/*
原始价为:60.0
---------------------------------
学生票:
折后价为:48.0
*/
}
}