File tree Expand file tree Collapse file tree 6 files changed +37
-16
lines changed
src/main/java/demo/invoice Expand file tree Collapse file tree 6 files changed +37
-16
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public class Invoice {
21
21
private BigDecimal totalAmount ;
22
22
23
23
/**
24
- * 火车票的专属字段,这个是否要抽到另一个对象里面?
24
+ * 火车票的专属字段
25
25
*/
26
26
private String trainNum ;
27
27
private String passengerName ;
Original file line number Diff line number Diff line change 3
3
/**
4
4
*
5
5
*/
6
- public class InvoiceTest {
6
+ public class InvoicePatternTest {
7
7
public static void main (String [] args ) {
8
- int invoiceType =8 ;
8
+ int invoiceType =9 ;
9
9
updateInvoice (invoiceType );
10
10
11
11
}
@@ -18,10 +18,11 @@ public static void updateInvoice(int invoiceType){
18
18
invoiceService =new InvoiceServiceAir ();
19
19
}else if (invoiceType ==9 ){
20
20
invoiceService =new InvoiceServiceTrain ();
21
+ }else {
22
+ invoiceService =new InvoiceServiceOther ();
21
23
}
22
24
invoiceService .updateInvoice ();
23
25
24
-
25
26
}
26
27
27
28
}
Original file line number Diff line number Diff line change 2
2
3
3
public interface InvoiceService {
4
4
5
- Invoice queryInvoice ();
5
+ Invoice queryInvoice (String invoiceNo , String invoiceCode );
6
6
7
7
int saveInvoice ();
8
8
9
9
int updateInvoice ();
10
10
11
- int insertInvoice ();
12
11
}
Original file line number Diff line number Diff line change 2
2
3
3
public class InvoiceServiceAir implements InvoiceService {
4
4
5
+
5
6
@ Override
6
- public Invoice queryInvoice () {
7
+ public Invoice queryInvoice (String invoiceNo , String invoiceCode ) {
8
+ System .out .println ("查询飞机票" );
7
9
return null ;
8
10
}
9
11
10
12
@ Override
11
13
public int saveInvoice () {
14
+ System .out .println ("保存飞机票" );
12
15
return 0 ;
13
16
}
14
17
15
18
@ Override
16
19
public int updateInvoice () {
20
+ System .out .println ("更新飞机票" );
17
21
return 0 ;
18
22
}
19
23
20
- @ Override
21
- public int insertInvoice () {
22
- return 0 ;
23
- }
24
24
}
Original file line number Diff line number Diff line change
1
+ package demo .invoice ;
2
+
3
+ public class InvoiceServiceOther implements InvoiceService {
4
+ @ Override
5
+ public Invoice queryInvoice (String invoiceNo , String invoiceCode ) {
6
+ System .out .println ("查询其他发票" );
7
+ return null ;
8
+ }
9
+
10
+ @ Override
11
+ public int saveInvoice () {
12
+ System .out .println ("保存其他发票" );
13
+ return 0 ;
14
+ }
15
+
16
+ @ Override
17
+ public int updateInvoice () {
18
+ System .out .println ("更新其他发票" );
19
+ return 0 ;
20
+ }
21
+
22
+ }
Original file line number Diff line number Diff line change 2
2
3
3
public class InvoiceServiceTrain implements InvoiceService {
4
4
@ Override
5
- public Invoice queryInvoice () {
5
+ public Invoice queryInvoice (String invoiceNo , String invoiceCode ) {
6
+ System .out .println ("查询火车票" );
6
7
return null ;
7
8
}
8
9
9
10
@ Override
10
11
public int saveInvoice () {
12
+ System .out .println ("保存火车票" );
11
13
return 0 ;
12
14
}
13
15
14
16
@ Override
15
17
public int updateInvoice () {
18
+ System .out .println ("更新火车票" );
16
19
return 0 ;
17
20
}
18
21
19
- @ Override
20
- public int insertInvoice () {
21
- return 0 ;
22
- }
23
22
}
You can’t perform that action at this time.
0 commit comments