zoukankan      html  css  js  c++  java
  • 设计模式之抽象工厂

    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();
            }
        }
    }
  • 相关阅读:
    implementaion bottle session with beaker
    [梦]20050802
    网站更新部署20100912
    Cherokee不值得推荐,你还是可以看一看
    最简单方法远程调试Python多进程子程序
    nginx相关的问题
    本地配置host解析的问题
    base target问题,
    在asp.net中自动合并小图片并使用css sprite显示出来
    html编辑器
  • 原文地址:https://www.cnblogs.com/bloodofhero/p/1520882.html
Copyright © 2011-2022 走看看