public class ApplePhone:MobilePhone
{
public ApplePhone()
{ }
public override void SendMessage()
{
Console.WriteLine("ApplePhone 现在已经具备了发送短信的功能");
}
public override void Call()
{
Console.WriteLine("ApplePhone 现在已经具备了普通通信的功能");
}
}
public class Bluetooth:Function
{
public Bluetooth(MobilePhone mobilephone)
: base(mobilephone)
{
Console.WriteLine("请您稍等,系统现在正在安装蓝牙功能");
Console.WriteLine("蓝牙功能添加成功");
}
public void Connect()
{
Console.WriteLine("蓝牙正在连接");
}
}
public class Camera:Function
{
public Camera(MobilePhone mobilephone)
: base(mobilephone)
{
Console.WriteLine("请您稍等,系统现在正在安装摄像头功能");
Console.WriteLine("摄像头功能添加成功");
}
public override void Take()
{
Console.WriteLine("通信功能升级为带有视频");
}
}
public class Function:MobilePhone
{
private MobilePhone _mobilephone;
public Function(MobilePhone mobilephone)
{
_mobilephone = mobilephone;
}
public override void SendMessage()
{
_mobilephone.SendMessage();
}
public override void Call()
{
_mobilephone.Call();
}
}
public class GPS:Function
{
public string Localtion { get; set; }
public GPS(MobilePhone mobilephone)
: base(mobilephone)
{
}
}
public class MiPhone:MobilePhone
{
public MiPhone()
{ }
public override void SendMessage()
{
Console.WriteLine("MiPhone 现在已经具备了发送短信的功能");
}
public override void Call()
{
Console.WriteLine("MiPhone 现在已经具备了普通通信的功能");
}
}
public abstract class MobilePhone
{
public MobilePhone()
{ }
//private string _Location; //存储将来需要拓展的定位数据
public abstract void SendMessage(); //发送短信
public abstract void Call(); //打电话
}
class Program
{
static void Main(string[] args)
{
MobilePhone mobilephone = new ApplePhone();
mobilephone.SendMessage();
mobilephone.Call();
Bluetooth bluetooth = new Bluetooth(mobilephone);
bluetooth.Connect();
GPS gps = new GPS(bluetooth);
gps.Localtion = "(3,4)";
Camera camera = new Camera(gps);
camera.Call();
Console.ReadLine();
}
}
原文:http://www.cnblogs.com/victorchi/p/5089989.html