Пример #1
0
        static void Main(string[] args)
        {
            #region 未使用简单工厂,则需要手动创建类
            var result = string.Empty;
            DatabaseConnection conn;

            conn   = new MySqConnection();
            result = conn.GetDatabaseConnection();
            Console.WriteLine(result);

            conn   = new SqlServerConnection();
            result = conn.GetDatabaseConnection();
            Console.WriteLine(result);
            #endregion


            #region 简单工厂模式写法

            var factory = DatabaseSourceFactory.GetDatabaseConnection("Mysql");
            result = factory.GetDatabaseConnection();
            Console.WriteLine(result);
            #endregion

            Console.ReadKey();
        }