• 代理模式 请勿饮酒


    行车不规范,情人两行泪!

    代理模式:

     public interface ICar
        {
            void Driver();
        }
    
        public class Car : ICar
        {
            public void Driver()
            {
                Console.WriteLine("Car is running");
            }
        }
        public enum State 
        {
            Normal,//正常
            Fatigue,//疲劳
            drinking //饮酒
        }
        public record Dirver(string Name , int Age, State state);
        public class CarProxy : ICar
        {
            private Dirver dirver;
    
            public CarProxy(Dirver dirver)
            {
                this.dirver = dirver;
            }
    
            public void Driver()
            {
                switch (dirver.state)
                {
                    case State.Normal:
                        new Car().Driver();
                        break;
                    case State.Fatigue:
                        Console.WriteLine($"Stop the Car!Name:{dirver.Name},Age:{dirver.Age} Please do not drive tired!!!");
                        break;
                    case State.drinking:
                        Console.WriteLine($"Police!!!Name:{dirver.Name},Age:{dirver.Age} Warning!Don't drive after drinking!!!");
                        break;
                    default:
                        break;
                }
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                var dirver1 = new Dirver("Mr.Zhang", 17, State.drinking);
                var dirver2 = new Dirver("Mr.Wang", 18, State.Normal);
                var dirver3 = new Dirver("Mr.Fang", 19, State.Fatigue);
                CarProxy carProxy = new CarProxy(dirver1);
                carProxy.Driver();
                carProxy = new CarProxy(dirver2);
                carProxy.Driver();
                carProxy = new CarProxy(dirver3);
                carProxy.Driver();
            }
        }
  • 相关阅读:
    上传文件事件并校验:event.target.files && event.target.files[0]
    深浅拷贝
    Git学习
    Flex弹性布局
    hive
    222
    错误总结
    Redis小结2
    spark小结
    kafka详解
  • 原文地址:https://www.cnblogs.com/Zingu/p/16291912.html
Copyright © 2020-2023  润新知