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");
            }

        }


    }

    肩负责任,永不退缩
  • 相关阅读:
    TcpClient
    文字识别
    halcon17.12 win7 64深度学框架搭建
    halcon多个形状模板匹配
    halcon 瓶盖定位
    halcol9点标定
    一个机械臂的正逆解
    Matlab robot-9.10(rvctools) 建模与正逆解
    16路舵机控制器USB访问
    C#二维码识别
  • 原文地址:https://www.cnblogs.com/ATP/p/860645.html
Copyright © 2011-2022 走看看