abstract class HandsetBrand
{
protected HandsetSoft soft;
public void SetHandsetSoft(HandsetSoft soft)
{
this.soft = soft;
}
public virtual void Run()
{
}
}
class HandsetBrandM:HandsetBrand
{
public override void Run()
{
Console.Write("手机M:");
soft.Run();
}
}
class HandsetBrandN:HandsetBrand
{
public override void Run()
{
Console.Write("手机N:");
soft.Run();
}
}
abstract class HandsetSoft
{
public abstract void Run();
}
class HandsetGame : HandsetSoft
{
public override void Run()
{
Console.WriteLine("运行游戏!");
}
}
class HandsetMP3 : HandsetSoft
{
public override void Run()
{
Console.WriteLine("运行手机MP3");
}
}
class Program
{
static void Main(string[] args)
{
HandsetSoft game = new HandsetGame();
HandsetSoft mp3 = new HandsetMP3();
HandsetBrandN n = new HandsetBrandN();
n.SetHandsetSoft(game);
n.Run();
n.SetHandsetSoft(mp3);
n.Run();
n.SetHandsetSoft(game);
HandsetBrandM m= new HandsetBrandM();
m.SetHandsetSoft(game);
m.Run();
m.SetHandsetSoft(mp3);
m.Run();
}
}