2008年7月20日

刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 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 Dr.Edison 阅读(142) | 评论 (8)编辑

今天总算闲下来 看看王涛的你必须知道的.net了 在OO大原则这一章节 看得尤为仔细 因为刚刚看完 程杰的那本小菜跟大鸟的书啊 在面向接口的时候 发现一个问题

  class Computeruse : IComputerLearn, IComputerToFun, IComputerWork
    
{
        
public Computeruse()
        
{
            Console.WriteLine(
"这个电脑我在用 别管我干嘛!!");
        }

        
    }

    
interface IComputerLearn
    
{
        
void ToLearn();
    }

    
interface IComputerWork
    
{
        
void ToWork();
    }

    
interface IComputerToFun
    
{
        
void ToFun();
    }

 我的一个类同时继承三个接口 但是我如何让这三个接口实现呢 就算我实例化一个ComputerUse对象 还是没有找到三个接口的实现方法 而且在类里面 也不能重载三个接口的方法 接口不是用来限制行为的吗? 怪事!还望高手能够赐教啊

posted @ 2008-07-20 10:13 Dr.Edison 阅读(151) | 评论 (5)编辑

公告

没事 走两步~

导航

<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

统计

与我联系

搜索

 

常用链接

留言簿

我参加的小组

我的标签

随笔档案

最新评论

阅读排行榜

评论排行榜