zoukankan      html  css  js  c++  java
  • 设计模式学习工厂模式

    1.概述

    工厂模式根据提供给他的数据,返回一个可能类中的一个类的实例。

    2.示例

     1using System;
     2using System.Collections.Generic;
     3using System.Linq;
     4using System.Text;
     5using System.Reflection; 
     6
     7namespace Factory
     8{
     9    class Program
    10    {
    11        public static readonly string DAL = "OracleDAL"
    12
    13        static void Main(string[] args)
    14        {
    15            IDAL dal = (IDAL)Assembly.Load("Factory").CreateInstance("Factory." + DAL);
    16            dal.DataAccess();
    17            Console.ReadKey();
    18        }

    19    }
     
    20
    21    public interface IDAL
    22    {
    23        void DataAccess();
    24    }
     
    25
    26    public class SqlServerDAL : IDAL
    27    {
    28        public void DataAccess()
    29        {
    30            Console.WriteLine("SqlServerDAL");
    31        }

    32    }
     
    33
    34    public class OracleDAL : IDAL
    35    {
    36        public void DataAccess()
    37        {
    38            Console.WriteLine("OracleDAL");
    39        }

    40    }

    41}

    42
  • 相关阅读:
    无废话XML阅读笔记(三)
    ____ To All Girls & Boys
    FDT注册码
    无废话XML阅读笔记(五)
    无废话XML阅读笔记(一)
    物理运动学公式汇总
    flash编译器错误查询表
    入秋了,给大家一些生活小常识
    12年
    linux 自动上传程序
  • 原文地址:https://www.cnblogs.com/celery94/p/1296655.html
Copyright © 2011-2022 走看看