/// <summary>
/// 抽象类:就是一个类,里面可以包含一切类的东西
/// </summary>
public abstract class Phone
{
public long Id { get; set; }
protected string Brand;
/// <summary>
/// 方法的多态,抽象方法,不同的子类进行不同的实现
/// </summary>
/// <returns></returns>
public abstract string System();
public void Call()
{
Console.WriteLine(
$"use {this.GetType().Name} {this.Brand} {this.System()} Call");
}
public void Photo()
{
Console.WriteLine(
$"use {this.GetType().Name} {this.Brand} {this.System()} Photo");
}
}
/// <summary>
/// 接口:不是一个类,不能包含具体实现,不能带访问修饰符
/// 通过接口,实现了对象与行为的分离,
/// 这样我们无须担心因为继承不当而使 某类 有 不该有的方法,保护了系统的完整性。
/// </summary>
public interface IExtend
{
/// <summary>
/// 属性
/// </summary>
string Remark { get; set; }
/// <summary>
/// 方法
/// </summary>
void FingerprintPayment();
/// <summary>
/// 事件
/// </summary>
event Action ea;
}
public class IPhone : Phone, IExtend
{
public IPhone() : base()
{
base.Brand = "Apple";
}
public string Remark { get; set; }
public event Action ea;
public void FingerprintPayment()
{
Console.WriteLine("指纹支付");
}
public override string System()
{
return "IOS";
}
}
public class Redmi : Phone
{
public Redmi()
{
base.Brand = "Redmi";
}
public override string System()
{
return "Android";
}
}
Phone iphone = new IPhone();
iphone.Call();
iphone.Photo();
Phone redmi = new Redmi();
iphone.Call();
iphone.Photo();
.NET 面向对象 之 继承,抽象类
最新推荐文章于 2024-05-13 17:03:57 发布