会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
About .NET
我的代码夹
博客园
首页
新随笔
联系
订阅
管理
面向接口编程之惑 第二版
刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 Vs 的智能提示 终于找到解决方法了 放代码出来啊 如果你刚看过那篇 你应该很清楚了啊
class
Program
{
static
void
Main(
string
[] args)
{
Computeruse com
=
new
Computeruse();
Adult me
=
new
Adult();
me.UseComputer(com);
Child mybrother
=
new
Child();
mybrother.UseComputer(com);
Console.ReadLine();
}
}
class
Computeruse : IFinal
{
public
Computeruse()
{
Console.WriteLine(
"
这个电脑我在用 别管我干嘛!!
"
);
}
IFinal 成员
#region
IFinal 成员
public
void
ToLearn()
{
Console.WriteLine(
"
我用电脑学习!
"
);
}
public
void
ToWork()
{
Console.WriteLine(
"
我用电脑工作!
"
);
}
public
void
ToFun()
{
Console.WriteLine(
"
我用玩游戏!
"
);
}
#endregion
}
interface
IFinal
{
void
ToLearn();
void
ToWork();
void
ToFun();
}
interface
IComputerLearn:IFinal
{
void
ToLearn();
}
interface
IComputerWork:IFinal
{
void
ToWork();
}
interface
IComputerToFun:IFinal
{
void
ToFun();
}
class
Adult
{
public
void
UseComputer(IFinal IFinal)
{
IFinal.ToLearn();
IFinal.ToFun();
}
}
class
Child
{
public
void
UseComputer( IFinal IFinal)
{
IFinal.ToFun();
}
}
这个应该是面向接口的最终版本了 希望下个项目会用到这个啊 呵呵~~
posted @
2008-07-20 10:40
tf.li
阅读(
327
) 评论(
8
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告