• 生产线模型


    模型如下:
    生产线(型号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");
            }

        }


    }

    肩负责任,永不退缩
  • 相关阅读:
    javascript 字符串截取
    HTML5 转
    Javascript try catch finally
    C#之json字符串转xml字符串
    AspNetCore Json序列化设置
    类加载(对象创建)顺序
    线性表,线性表和链表的区别
    Implement int sqrt(int x).
    Add Binary
    Roman to Integer(将罗马数字转成整数)
  • 原文地址:https://www.cnblogs.com/ATP/p/860645.html
Copyright © 2020-2023  润新知