设计模式之抽象工厂
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignPattern
{
public interface CellPhone
{
void Talk(string mes);
void Send(string mes);
}
public interface Computer
{
void Play(string mes);
void Work(string mes);
}
public interface User
{
void SendMessage(CellPhone phone, string mes);
void PlayGame(Computer computer, string mes);
}
public class Nokia : CellPhone
{
public void Talk(string mes)
{
Console.WriteLine("Nokia talk:" + mes);
}
public void Send(string mes)
{
Console.WriteLine("Nokia send:" + mes);
}
}
public class Moto : CellPhone
{
public void Talk(string mes)
{
Console.WriteLine("Moto talk:" + mes);
}
public void Send(string mes)
{
Console.WriteLine("Moto send:" + mes);
}
}
public class Dell : Computer
{
public void Play(string mes)
{
Console.WriteLine("Dell play:" + mes);
}
public void Work(string mes)
{
Console.WriteLine("Dell Work:" + mes);
}
}
public class Lenovo : Computer
{
public void Play(string mes)
{
Console.WriteLine("Lenovo play:" + mes);
}
public void Work(string mes)
{
Console.WriteLine("Lenovo work:" + mes);
}
}
public class Student : User
{
public void SendMessage(CellPhone phone, string mes)
{
phone.Send(mes);
}
public void PlayGame(Computer computer, string mes)
{
computer.Play(mes);
}
}
class Program
{
static void Main(string[] args)
{
Lenovo lenovo = new Lenovo();
Nokia nokia = new Nokia();
Student zhangsan = new Student();
zhangsan.PlayGame(lenovo, "大话西游");
zhangsan.SendMessage(nokia, "我不在家");
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignPattern
{
public interface CellPhone
{
void Talk(string mes);
void Send(string mes);
}
public interface Computer
{
void Play(string mes);
void Work(string mes);
}
public interface User
{
void SendMessage(CellPhone phone, string mes);
void PlayGame(Computer computer, string mes);
}
public class Nokia : CellPhone
{
public void Talk(string mes)
{
Console.WriteLine("Nokia talk:" + mes);
}
public void Send(string mes)
{
Console.WriteLine("Nokia send:" + mes);
}
}
public class Moto : CellPhone
{
public void Talk(string mes)
{
Console.WriteLine("Moto talk:" + mes);
}
public void Send(string mes)
{
Console.WriteLine("Moto send:" + mes);
}
}
public class Dell : Computer
{
public void Play(string mes)
{
Console.WriteLine("Dell play:" + mes);
}
public void Work(string mes)
{
Console.WriteLine("Dell Work:" + mes);
}
}
public class Lenovo : Computer
{
public void Play(string mes)
{
Console.WriteLine("Lenovo play:" + mes);
}
public void Work(string mes)
{
Console.WriteLine("Lenovo work:" + mes);
}
}
public class Student : User
{
public void SendMessage(CellPhone phone, string mes)
{
phone.Send(mes);
}
public void PlayGame(Computer computer, string mes)
{
computer.Play(mes);
}
}
class Program
{
static void Main(string[] args)
{
Lenovo lenovo = new Lenovo();
Nokia nokia = new Nokia();
Student zhangsan = new Student();
zhangsan.PlayGame(lenovo, "大话西游");
zhangsan.SendMessage(nokia, "我不在家");
Console.ReadLine();
}
}
}