C# 代理模式 RealSubject.cs

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

namespace ProxyModelDemo
{
    /// <summary>
    /// 业务类
    /// </summary>
    public class RealSubject : ISubject
    {
        public RealSubject()
        {
            System.Threading.Thread.Sleep(2000);
            long lResult = 0;
            for (int i = 0; i < 1000000; i++)
            {
                lResult += i;
            }
            Console.WriteLine("RealSubject被构造...");
        }
        /// <summary>
        /// 一个耗时的操作
        /// </summary>
        public void DoSomethingLong()
        {
            Console.WriteLine("下订单...");
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("短信通知...");
            System.Threading.Thread.Sleep(1000);
        }
        /// <summary>
        /// 一个耗时的查询
        /// </summary>
        /// <returns></returns>
        public List<string> GetSomethingLong()
        {
            Console.WriteLine("读取大文件信息...");
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("数据库大数据查询...");
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("调用远程接口...");
            System.Threading.Thread.Sleep(1000);

            Console.WriteLine("最终合成结果,一堆的商品列表");
            return new List<string>() { "123", "456", "789" };
        }
    }
}
 

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/89428659