using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
/// <summary>
/// 定义一个会议接口
/// </summary>
public interface IMeeting
{
/// <summary>
/// 演讲
/// </summary>
void Speech();
/// <summary>
/// 讨论
/// </summary>
/// <param name="topic"></param>
/// <returns></returns>
string Talk(string topic);
//根据需要在继续添加...
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
/// <summary>
/// 教学相关的接口
/// </summary>
public interface ITeach
{
/// <summary>
/// 教学研究
/// </summary>
void StudyCourse();
/// <summary>
/// 组织考试
/// </summary>
/// <param name="term"></param>
/// <returns></returns>
bool Exam(string term);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
public abstract class Person
{
public Person() { }
public Person(string idNo, string name)
{
this.IDNo = idNo;
this.Name = name;
}
public string IDNo { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
//这两个是抽像方法
public abstract void Dowork();
public abstract void Rest();
//虚方法
public virtual string GetInfo()
{
return $"编号:{IDNo } 姓名:{Name}";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
public class Dean : IMeeting
{
public void Speech()
{
Console.WriteLine($"主任正在演讲...");
}
public string Talk(string topic)
{
return $"主任正在讨论针对 {topic} ...";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
public class President : Person, IMeeting
{
public President() { }
public President(string name) { this.Name = name; }
public override void Dowork()
{
Console.WriteLine("校长开始工作...");
}
public override void Rest()
{
Console.WriteLine("校长下班休息...");
}
//实现接口
public void Speech()
{
Console.WriteLine($"{Name} 校长正在演讲...");
}
public string Talk(string topic)
{
return $"{Name} 校长正在讨论针对 {topic} ...";
}
显示实现接口:通常是你实现了两个或两个以上的接口类,但是这些接口类中,有相同的方法
//void IMeeting.Speech()
//{
// throw new NotImplementedException();
//}
//string IMeeting.Talk(string topic)
//{
// throw new NotImplementedException();
//}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace thinger.cn.TeachDemo03
{
public class Teacher : Person, IMeeting,ITeach
{
//特有的属性
public string Post { get; set; }
public string PhoneNumber { get; set; }
public Teacher()
{ }
public Teacher(string name)
{
this.Name = name;
}
public Teacher(string name, string phone)
{
this.Name = name;
this.PhoneNumber = phone;
}
//特有的方法
public void Lecture()
{
Console.WriteLine($"【子类】方法输出:{Name} 正在授课... ");
}
/// <summary>
/// 重写父类的方法
/// </summary>
public override void Dowork()
{
Console.WriteLine("老师开始工作...");
}
public override void Rest()
{
Console.WriteLine("老师下班休息...");
}
/// <summary>
/// 来自IMeeting接口实现方法1:演讲
/// </summary>
public void Speech()
{
Console.WriteLine($"{Name} 老师正在演讲...");
}
/// <summary>
/// 来自IMeeting接口实现方法2:讨论
/// </summary>
/// <param name="topic"></param>
/// <returns></returns>
public string Talk(string topic)
{
return $"{Name} 老师正在讨论针对 {topic} ...";
}
/// <summary>
/// 来自ITeach的接口实现方法1:教学研究
/// </summary>
public void StudyCourse()
{
Console.WriteLine("老师正在研究教学内容...");
}
/// <summary>
/// 来自ITeach的接口实现方法2:组织考试
/// </summary>
/// <param name="term"></param>
/// <returns></returns>
public bool Exam(string term)
{
//其他相关的业务处理。。。。
return true;
}
}
}
protected
抽象方法:abstract
虚方法:virtual
重写:override
接口:Interface