惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
D
Docker
J
Java Code Geeks
腾讯CDC
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
M
MIT News - Artificial intelligence
L
LangChain Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
博客园 - Franky
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
N
Netflix TechBlog - Medium
B
Blog RSS Feed
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News

博客园 - tf.li

清理MVC4 Internaet 项目模板清理 SQL2014 尝试读取或写入受保护的内存。这通常指示其他内存已损坏 nodejs 环境配置技巧 mongdb window 服务安装批处理 bower 安装后 jade 引用404问题 我的Prototype模式框架 转自CnBeta 令人深思 [译稿]为什么我们不要 .NET 程序员 JSON.NET、WebService与JQuery协同工作 我修改的IP地址掩码 呵呵~~开心 Ext.Ajax.request 传值问题 从小做大之一---------一切从建模开始 [求助]关于文本行转列的疑问~~ To Terrylee 我的设计模型之小议工厂模式 我的设计模型之装饰者模式 我对线程池的一点理解 面向接口编程之惑 我的设计模型之适配器模式 我的设计模型之简单工厂
面向接口编程之惑 第二版
tf.li · 2008-07-20 · via 博客园 - tf.li

面向接口编程之惑 第二版

刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 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 成员
    }

    
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  阅读(357)  评论(8)    收藏  举报

刷新页面返回顶部