C#学习小记13接口的包容!像个泡菜坛子!

//接口的包容.
using System;
public interface ITeacher
{
bool AgreeToTeach();     
void Print(string b);   
}                        
public class Professor:ITeacher     
{
private int course;
public int Course
{
   set{course=value;}
   get{return course;}
}
public bool AgreeToTeach()  
{
   if(Course==1)
     return true;
   else
     return false;
}
public void Print(string a)
{
   Console.WriteLine(this.AgreeToTeach()+a);
}
}
public class Student:ITeacher     
{
private int course;
public int Course
{
   set{course=value;}
   get{return course;}
}
public bool AgreeToTeach()  
{
   if(Course==1)
     return true;
   else
     return false;
}
public void Print(string a)
{
   Console.WriteLine(this.AgreeToTeach()+a);
}
}
public class Do
{
private ITeacher teach;
public ITeacher Teach
{
   get{return teach;}
   set{teach=value;}
}
static void Main()
{
   Do c=new Do();
   Professor p=new Professor();
   c.Teach=p;
   c.Teach.Print("professor");
   Student m=new Student();
   c.Teach=m;
   c.Teach.Print("student");
}
}


posted on 2008-08-06 13:29  yatasoft  阅读(167)  评论(0编辑  收藏  举报

导航