• 设计模式


    1.外观模式

     public class ChargeBillFacadeService
        {
    
            private ChaegeBillServiceFactory chaegeBillServiceFactory;
    
            public ChargeBillFacadeService()
            {
                this.chaegeBillServiceFactory = new ChaegeBillServiceFactory();
            }
    
    
            public CM_ChargeBilsEntity GetChargeBill(string id)
            {
                ChargeQueryService chargeQueryService = chaegeBillServiceFactory.GetService<ChargeQueryService>("4");
                return chargeQueryService.GetChargeBill(id);
            }
    
            public List<CM_ChargeBilsDetailEntity> GetChargeBillData(string id)
            {
                ChargeQueryService chargeQueryService = chaegeBillServiceFactory.GetService<ChargeQueryService>("4");
                return chargeQueryService.GetChageBillData(id);
            }
    
            public int UpdatePushStatus(string id, Dictionary<string, string> dic)
            {
                ChargeBillUpdateService chargeBillUpdateService = chaegeBillServiceFactory.GetService<ChargeBillUpdateService>("3");
                return chargeBillUpdateService.UpdateChargeBill(id, dic);
            }
            public int UpdateChargeBill(string id, Dictionary<string, string> dic)
            {
                ChargeBillUpdateService chargeBillUpdateService = chaegeBillServiceFactory.GetService<ChargeBillUpdateService>("3");
                return chargeBillUpdateService.UpdateChargeBill(id, dic);
            }
    
            public void UpdateChargeBill(string[] ids)
            {
                ChargeBillDeleteService chargeBillDeleteService = chaegeBillServiceFactory.GetService<ChargeBillDeleteService>("2");
                chargeBillDeleteService.DeleteChargeBill(ids);
            }
    
            public void SaveChargeBill(CM_ChargeBilsEntity model, CM_ChargeBilsDetailEntity modelData)
            {
                IChargeBillSaveService chargeBillSaveService = chaegeBillServiceFactory.GetService<IChargeBillSaveService>("1");
                chargeBillSaveService.SaveChargeBill(model);
                chargeBillSaveService.SaveChargeBillDetail(modelData);
            }
        }
    
        public class StartChargeService
        {
            ChargeBillFacadeService chargeBillFacadeService;
            public StartChargeService()
            {
                chargeBillFacadeService = new ChargeBillFacadeService();
            }
            public void StartCharge()
            {
                chargeBillFacadeService.SaveChargeBill(new CM_ChargeBilsEntity(), new CM_ChargeBilsDetailEntity());
            }
        }
    
        public class PowerUpdateService
        {
            ChargeBillFacadeService chargeBillFacadeService;
            public PowerUpdateService()
            {
                chargeBillFacadeService = new ChargeBillFacadeService();
            }
            public void PowerUpdate()
            {
                chargeBillFacadeService.UpdatePushStatus("1", new Dictionary<string, string>());
                chargeBillFacadeService.UpdateChargeBill("1", new Dictionary<string, string>());
            }
        }
    
        public class StopChargeService
        {
            ChargeBillFacadeService chargeBillFacadeService;
            public StopChargeService()
            {
                chargeBillFacadeService = new ChargeBillFacadeService();
            }
            public void StopCharge()
            {
                chargeBillFacadeService.UpdateChargeBill("1", new Dictionary<string, string>());
                chargeBillFacadeService.SaveChargeBill(new CM_ChargeBilsEntity(), new CM_ChargeBilsDetailEntity());
            }
        }
    
        public class ChaegeBillServiceFactory
        {
            public IChargeBillDeleteService GetDelectService()
            {
                return new ChargeBillDeleteService();
            }
    
            public IChargeBillUpdateService GetUpdateService()
            {
                return new ChargeBillUpdateService();
            }
    
            public IChargeQueryService GetQueryService()
            {
                return new ChargeQueryService();
            }
            public IChargeBillSaveService GetSaveService()
            {
                return new ChargeBillSaveService();
            }
    
            public T GetService<T>(string type)
            {
                if (type == "1")
                {
                    return (T)GetSaveService();
                }
                else if (type == "2")
                {
                    return (T)GetDelectService();
                }
                else if (type == "3")
                {
                    return (T)GetUpdateService();
                }
                else
                {
                    return (T)GetQueryService();
                }
                return default(T);
    
            }
        }
    
        public class ChargeBillDeleteService : IChargeBillDeleteService
        {
            public void DeleteChargeBill(string[] ids)
            {
            }
        }
    
        public class ChargeBillUpdateService : IChargeBillUpdateService
        {
            public int UpdateChargeBill(string id, Dictionary<string, string> dic)
            {
                return 1;
            }
            public int UpdatePushStatus(string id, int state)
            {
                return 1;
            }
        }
    
    
        public class ChargeQueryService : IChargeQueryService
        {
            public CM_ChargeBilsEntity GetChargeBill(string id)
            {
                return new CM_ChargeBilsEntity();
            }
            public List<CM_ChargeBilsDetailEntity> GetChageBillData(string id)
            {
                return new List<CM_ChargeBilsDetailEntity>();
            }
        }
    
        public class ChargeBillSaveService : IChargeBillSaveService
        {
    
            public void SaveChargeBill(CM_ChargeBilsEntity model) { }
            public void SaveChargeBillDetail(CM_ChargeBilsDetailEntity model) { }
        }
    
    
    
        public interface IChargeBillSaveService
        {
            void SaveChargeBill(CM_ChargeBilsEntity model);
            void SaveChargeBillDetail(CM_ChargeBilsDetailEntity model);
        }
    
    
    
    
        public interface IChargeQueryService
        {
            CM_ChargeBilsEntity GetChargeBill(string id);
            List<CM_ChargeBilsDetailEntity> GetChageBillData(string id);
        }
    
    
    
    
        public interface IChargeBillUpdateService
        {
            int UpdateChargeBill(string id, Dictionary<string, string> dic);
            int UpdatePushStatus(string id, int state);
        }
    
        public interface IChargeBillDeleteService
        {
            void DeleteChargeBill(string[] ids);
        }
    
        public class CM_ChargeBilsEntity { }
        public class CM_ChargeBilsDetailEntity { }

    2.代理模式

      // 客户端调用
        class Client
        {
            static void Main(string[] args)
            {
                ITaskSerderService taskSerderService = new TaskSerderService();
                ServiceProxy serviceProxy = new ServiceProxy(taskSerderService);
                serviceProxy.Send(new Task());
    
            }
        }
    
        public interface ITaskSerderService
        {
            void Send(ITask task);
        }
    
    
        public class TaskSerderService : ITaskSerderService
        {
            public void Send(ITask task)
            {
                //do .......
            }
        }
        /// <summary>
        ///代理类
        /// </summary>
    
        public class ServiceProxy : ITaskSerderService
        {
            private ITaskSerderService taskSerderService;
            public ServiceProxy(ITaskSerderService taskSerderService)
            {
                this.taskSerderService = taskSerderService;
            }
            public void Send(ITask task)
            {
                taskSerderService.Send(task);
            }
        }
  • 相关阅读:
    Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory
    Spring源码情操陶冶-AbstractApplicationContext#prepareRefresh
    Spring源码情操陶冶-AbstractApplicationContext
    Spring源码情操陶冶-ContextLoader
    Spring源码情操陶冶-ContextLoaderListener
    Spring mybatis源码篇章-MapperScannerConfigurer
    Spring mybatis源码篇章-动态SQL节点源码深入
    Spring mybatis源码篇章-动态SQL基础语法以及原理
    Spring mybatis源码篇章-Mybatis的XML文件加载
    Spring mybatis源码篇章-Mybatis主文件加载
  • 原文地址:https://www.cnblogs.com/-alvin/p/14135230.html
Copyright © 2020-2023  润新知