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

        }


    }

    肩负责任,永不退缩
  • 相关阅读:
    3. 无重复字符的最长子串
    字节跳动 最小栈
    排序
    线程的优先级
    线程的操作方法
    线程的生命周期
    实现线程的方式:Thread类重写run();Runnable类重写run();Callable类重写call();实现线程的方式
    Java thread run() start() 是干什么的以及区别
    Java thread 多线程
    助教工作学期总结
  • 原文地址:https://www.cnblogs.com/ATP/p/860645.html
Copyright © 2011-2022 走看看