zoukankan
html css js c++ java
面向接口编程之惑 第二版
刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 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();
}
}
这个应该是面向接口的最终版本了 希望下个项目会用到这个啊 呵呵~~
查看全文
相关阅读:
算法导论6.33习题解答
最短子序列(最短摘要)
算法导论83(b)习题解答(trie树)
算法导论61习题解答
算法导论8.24习题解答(计数排序)
算法导论8.34习题解答(基数排序)
算法导论6.57习题解答
算法导论63习题解答(Young氏矩阵)
算法导论6.58习题解答(最小堆K路合并)
算法导论6.17习题解答
原文地址:https://www.cnblogs.com/DrEdison/p/1246949.html
最新文章
心有余而力不足
坚持
广州电信最新DNS更新
转脱壳方法
招聘
广州电信最新DNS更新
Microsoft JET Database Engine 错误 '80040e09' 解决方法
招聘
心有余而力不足
delphi中Treeview的使用介绍
热门文章
delphi treeview添加节点_一片树叶
如何在ToolBar中显示文字和图标,自定义图标大小,并和MenuItem关联
Delphi 中递归生成TreeView节点的方法
Fastreport使用经验(转) 在Delphi程序中访问报表对象
delphi中的key值
Lookup和Locate方法使用
数据库表TreeView树的快速生成
Delphi实现树型结构
FastReport的使用方法
算法导论7.14习题解答(快速排序)
Copyright © 2011-2022 走看看