zoukankan      html  css  js  c++  java
  • 我的设计模型之简单工厂

    抽象工厂模型 了解设计模型的人都该清楚啊 代码自己打一下 比较清楚啊

      using
     System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace 抽象工厂
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                Console.WriteLine(
    "请输入你要购买的水果:");
                
    string FruitName = Console.ReadLine();
                IFruit Fruit 
    = null;
                FruitFactory MyFactory 
    = new FruitFactory();
                
    switch (FruitName) 
                    
    case "苹果":
                        Fruit 
    = MyFactory.MakeApple();
                        
    break;
                    
    case "橘子":
                        Fruit 
    = MyFactory.MakeOrange();
                        
    break;
                    
    default:
                        Console.WriteLine(
    "别瞎写 就两种水果!");
                        
    break;
                }

                Console.ReadLine();
            }

        }

        
    interface IFruit 
        
        }

        
    public class Apple : IFruit 
         
    public Apple(){
             Console.WriteLine(
    "An Apple is Got!");
          }

        }

        
    public class Orange : IFruit {
            
    public Orange() {
                Console.WriteLine(
    "An Orange is Got!");
            }

        }

        
    public class FruitFactory {
            
    public Apple MakeApple() {
                
    return new Apple();
            }

            
    public Orange MakeOrange() {
                
    return new Orange();
            }

        }

    }

  • 相关阅读:
    WPF 如何创建自己的WPF自定义控件库
    浅谈WPF的VisualBrush
    从Oracle数据库中查询前几个月数据时需要注意的一些问题
    WPF当属性值改变时利用PropertyChanged事件来加载动画
    java array to list
    nGrinder 简易使用教程
    页面json 格式化+颜色高亮
    通过maven test 报org.apache.ibatis.binding.BindingException: Invalid bound statement
    jenkins 多选框
    jstack jstat 简易使用教程
  • 原文地址:https://www.cnblogs.com/DrEdison/p/1191289.html
Copyright © 2011-2022 走看看