zoukankan      html  css  js  c++  java
  • 生产线模型

    模型如下:
    生产线(型号A)———〉生产汽车(型号A)———〉测试汽车(型号A)
    要求:当更换生产线时对程序的改动要尽可能的少
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                
    string NO;
                NO 
    = Console.ReadLine();
                
    try
                
    {
                    Produce(NO).MakeCar();
                    Produce(NO).TestCar();
                }

                
    catch (NullReferenceException e)
                
    {
                    Console.WriteLine(e.Message);
                }

                       
            }

            
    static IProductLine Produce(string No)
            
    {
                
    if (No == "2000")
                
    {
                    
    return new Car_2000();
                }

                
    else if (No == "3000")
                
    {
                    
    return new Car_3000();
                }

                
    else
                
    {
                    Console.WriteLine(
    "你输入的型号不正确!");
                    
    return null;

                }

            }

        }

        
    interface IProductLine
        
    {
            
    void MakeCar();
            
    void TestCar();
        }

        
    class Car_2000 : IProductLine
        
    {
            
    public void MakeCar()
            
    {
                Console.WriteLine(
    "make car 2000");
            }

            
    public void TestCar()
            
    {
                Console.WriteLine(
    "test car 2000");
            }

        }

        
    class Car_3000 : IProductLine
        
    {
            
    public void MakeCar()
            
    {
                Console.WriteLine(
    "make car 3000");
            }

            
    public void TestCar()
            
    {
                Console.WriteLine(
    "test car 3000");
            }

        }


    }

    肩负责任,永不退缩
  • 相关阅读:
    生产者-消费者模型-线程安全队列Queue
    多线程简单案例
    cloudstack 用admin 账号创建虚拟机只是提示insufficient resource
    什么是工厂函数?Python 中工厂函数怎么理解?(转)
    rsync + mysql + gzip + --single-transaction
    Python中获取异常(try Exception)信息
    ansible copy 模块 changed false 没有变化
    _mysql.c:29:20: error: Python.h: No such file or directory
    常用网址
    Android 中常见控件的介绍和使用
  • 原文地址:https://www.cnblogs.com/ATP/p/860645.html
Copyright © 2011-2022 走看看