Skip to content

Commit a11050c

Browse files
committed
1 parent 7c34326 commit a11050c

24 files changed

+534
-0
lines changed

FactoryAndProxy/src/Main.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.io.UnsupportedEncodingException;
2+
import java.net.URLDecoder;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws UnsupportedEncodingException {
7+
// Pay a = PayWayFactorys.buyer(new WxPayFactory());
8+
// Pay b = PayWayFactorys.buyer(new ZfbPayFactory());
9+
// PayFactory zfbF = new ZfbPayFactory();
10+
// Pay ab = zfbF.getPay();
11+
// ab.pay();;
12+
//
13+
// Person p = PersonFactory.getPersonInstance();
14+
// p.say();
15+
// Person p2 = PersonFactory.getPersonInstance();
16+
// System.out.println(p == p2);
17+
// Person p3 = Person.getPerson();
18+
// System.out.println(p3 == p2);
19+
String sf = "service=page/component.Navigation&listener=opencontent&title=手工收退费&url=custserv?service=page/personalserv.handrecedefee.HandRecedeFee&listener=initMobTrade&listener=&RIGHT_CODE=csHandRecedeFee&staffId=baiss3&departId=11b1jz1&subSysCode=custserv&eparchyCode=0010";
20+
System.out.println(sf.indexOf("&title="));
21+
System.out.println(sf.lastIndexOf("&url="));
22+
String title = URLDecoder.decode(sf.substring(sf.indexOf("&title=") + 7, sf.lastIndexOf("&url=")), "GBK");
23+
System.out.println(title);
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 接口类
11+
*/
12+
public interface Pay {
13+
public void pay();
14+
public void payNum();
15+
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 工厂类接口
11+
*/
12+
public interface PayFactory {
13+
Pay getPay();
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 工厂实体类
11+
*/
12+
public class PayWayFactorys {
13+
public static Pay buyer (PayFactory pf){
14+
Pay pay = pf.getPay();
15+
return pay;
16+
}
17+
public static PayFactory getWxPayFactory(){
18+
return new ZfbPayFactory();
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 具体产品角色
11+
*/
12+
public class WXPay implements Pay {
13+
@Override
14+
public void pay() {
15+
System.out.println("WX Pay");
16+
}
17+
18+
@Override
19+
public void payNum() {
20+
System.out.println("Wx Pay 4");
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
public class WxPayFactory implements PayFactory {
9+
@Override
10+
public Pay getPay() {
11+
return new WXPay();
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 具体产品角色
11+
*/
12+
public class ZfbPay implements Pay{
13+
@Override
14+
public void pay() {
15+
System.out.println("ZFB Pay");
16+
}
17+
18+
@Override
19+
public void payNum() {
20+
System.out.println("ZFB BUY 2");
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package methodFactory;
2+
3+
/**
4+
* @author : mayuan
5+
* @description :
6+
* @date : 2018/3/6
7+
*/
8+
9+
/**
10+
* 工厂类
11+
*/
12+
public class ZfbPayFactory implements PayFactory {
13+
@Override
14+
public Pay getPay() {
15+
return new ZfbPay();
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package nomal;
2+
3+
/**
4+
* @author : huangchen
5+
* @description :
6+
* @date : 2018/3/5
7+
*/
8+
public class WxPay {
9+
public void pay(){
10+
System.out.println("微信支付");
11+
}
12+
public void byWhat(String thing){
13+
System.out.println("微信买了"+thing);
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package nomal;
2+
3+
/**
4+
* @author : huangchen
5+
* @description :
6+
* @date : 2018/3/5
7+
*/
8+
public class ZfbPay {
9+
public void pay(){
10+
System.out.println("支付宝支付");
11+
}
12+
13+
public void byWhat(String thing){
14+
System.out.println("支付宝买了"+thing);
15+
}
16+
}

0 commit comments

Comments
 (0)