static void Main(string[] args) { Param param = new Param() { Table = "Person", Column = "Name", Key = "Id" }; DataBase db = new MyDataBase(); LogDecorator logDecorator = new LogDecorator(db); ExceptionDecorator exceptionDecorator = new ExceptionDecorator(logDecorator); logDecorator.Query(param); try { exceptionDecorator.Query(param); } catch (DataBaseException e) { Console.WriteLine("Error: " + e.Message); } }
static void Main(string[] args) { //首先实现一个具体的猫 Animal duck = new Duck { FootNum = 2, HaveTail = true, Name = "鸭子" }; //再装饰一个日志 duck = new LogDecorator(duck); //装饰一个时间戳 duck = new TimeStampDecorator(duck); duck.Sound(); Console.Read(); }