java技術博客
jsp博客
BlogJava
首頁
新隨筆
聯系
聚合
管理
數據加載中……
java代理模式
package
orj.jzkangta.proxydemo02;
public
class
ComputerMaker
implements
SaleComputer
{
public
void
sale(String type)
{
System.out.println(
"
賣出了一臺
"
+
type
+
"
電腦
"
);
}
}
package
orj.jzkangta.proxydemo02;
import
java.lang.reflect.Proxy;
public
class
ComputerProxy
{
public
static
SaleComputer getComputerMaker()
{
ProxyFunction pf
=
new
ProxyFunction();
return
(SaleComputer)Proxy.newProxyInstance(ComputerMaker.
class
.getClassLoader(), ComputerMaker.
class
.getInterfaces(), pf);
}
}
package
orj.jzkangta.proxydemo02;
import
java.lang.reflect.InvocationHandler;
import
java.lang.reflect.Method;
public
class
ProxyFunction
implements
InvocationHandler
{
private
ComputerMaker cm;
public
void
youHui()
{
System.out.println(
"
我給你一些優惠。。。
"
);
}
public
void
giveMouse()
{
System.out.println(
"
我還要送你一個鼠標。。。
"
);
}
public
Object invoke(Object arg0, Method arg1, Object[] arg2)
throws
Throwable
{
String type
=
(String)arg2[
0
];
if
(type.equals(
"
聯想
"
)
||
type.equals(
"
三星
"
))
{
if
(cm
==
null
)
{
cm
=
new
ComputerMaker();
youHui();
giveMouse();
arg1.invoke(cm, type);
}
}
else
{
System.out.println(
"
我沒有你要的這個牌子的電腦。。。。
"
);
}
return
null
;
}
}
package
orj.jzkangta.proxydemo02;
public
interface
SaleComputer
{
public
void
sale(String type);
}
package
orj.jzkangta.proxydemo02;
public
class
Test
{
public
static
void
main(String[] args)
{
SaleComputer sc
=
ComputerProxy.getComputerMaker();
//
sc.sale("聯想");
//
sc.sale("三星");
sc.sale(
"
Dell
"
);
}
}
posted on 2008-10-31 07:49
郭興華
閱讀(727)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 郭興華
<
2008年10月
>
日
一
二
三
四
五
六
28
29
30
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
26
27
28
29
30
31
1
2
3
4
5
6
7
8
統計
隨筆 - 84
文章 - 1
評論 - 2
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
java每日練習代碼
(rss)
TESTARRAY(6)
(rss)
事件模型與事件處理
(rss)
隨筆檔案
2009年1月 (2)
2008年11月 (14)
2008年10月 (68)
文章檔案
2008年10月 (1)
搜索
最新評論
1.?re: jsp讀取*.TXT
請問 retstr是什么數據類型?String?好像不行哦
--jsp
2.?re: StudentTest1.java
看不懂你的意思,代碼沒有縮進,看著很不習慣那。
--楊愛友
閱讀排行榜
1.?java中的treemap(4605)
2.?JDBC連接SQLSERVER(1822)
3.?判斷一個一個路徑是否是目錄(1085)
4.?jsp讀取*.TXT(765)
5.?java代理模式(727)
評論排行榜
1.?StudentTest1.java(1)
2.?jsp讀取*.TXT(1)
3.?java1.5注解(二)(0)
4.?java1.5注解(一)(0)
5.?jsp中使用類(0)
主站蜘蛛池模板:
芷江
|
石城县
|
夏河县
|
屏边
|
淮安市
|
抚远县
|
和政县
|
喀喇
|
昌吉市
|
宜都市
|
麻栗坡县
|
玉环县
|
博白县
|
辉南县
|
临朐县
|
博湖县
|
花莲县
|
兴和县
|
孙吴县
|
汾阳市
|
阜新市
|
依安县
|
吉安县
|
深州市
|
白沙
|
岑巩县
|
桂东县
|
绥芬河市
|
廊坊市
|
龙门县
|
天镇县
|
波密县
|
龙南县
|
酉阳
|
绥棱县
|
阜宁县
|
衡阳县
|
宁城县
|
青田县
|
乐清市
|
肥东县
|