会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
About .NET
我的代码夹
博客园
首页
新随笔
联系
订阅
管理
我的设计模型之简单工厂
抽象工厂模型 了解设计模型的人都该清楚啊 代码自己打一下 比较清楚啊
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
抽象工厂
{
class
Program
{
static
void
Main(
string
[] args)
{
Console.WriteLine(
"
请输入你要购买的水果:
"
);
string
FruitName
=
Console.ReadLine();
IFruit Fruit
=
null
;
FruitFactory MyFactory
=
new
FruitFactory();
switch
(FruitName)
{
case
"
苹果
"
:
Fruit
=
MyFactory.MakeApple();
break
;
case
"
橘子
"
:
Fruit
=
MyFactory.MakeOrange();
break
;
default
:
Console.WriteLine(
"
别瞎写 就两种水果!
"
);
break
;
}
Console.ReadLine();
}
}
interface
IFruit
{
}
public
class
Apple : IFruit
{
public
Apple()
{
Console.WriteLine(
"
An Apple is Got!
"
);
}
}
public
class
Orange : IFruit
{
public
Orange()
{
Console.WriteLine(
"
An Orange is Got!
"
);
}
}
public
class
FruitFactory
{
public
Apple MakeApple()
{
return
new
Apple();
}
public
Orange MakeOrange()
{
return
new
Orange();
}
}
}
posted @
2008-05-10 15:31
tf.li
阅读(
361
) 评论(
1
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告