http://baike.baidu.com/link?url=iUjCghjjxhFzN6SOU7pfeSJsBhe3gFVte19Z1vb7As6q98shu_NB2ZJ7-uuFXEZhf5G-pv3TzuOCQ8ZMm8iwCRhKWMwWoItfxD6jWGEwrHic2l2H5hqxAH90GYfMPixO0NEvZEzYt-0weW1OiUgS5R2TkSWlPVz3ZAny1Eld80eJuGVYpX2VCJCklpfhigZt
1
2
3
4
5
6
7
8
9
10
11
|
classA
{
AInterface a;
A(){}
AMethod()
//一个方法
{
a =
new
AInterfaceImp();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
InterfaceImplFactory
{
AInterface create(Object condition)
{
if
(condition = condA)
{
return
new
AInterfaceImpA();
}
else
if
(condition = condB)
{
return
new
AInterfaceImpB();
}
else
{
return
new
AInterfaceImp();
}
}
}
|