Program.cs

class Program
{
  static void Main(string[] args)
  {
    User user = " };
    var processor = TransparentProxy.Create<UserProcessor>();
    processor.Shopping(user);
    Console.ReadLine();
  }
}

User.cs

public class User
{
    public string Name { get; set; }

    public string Password { get; set; }
}

IUserProcessor.cs

public interface IUserProcessor
{
  void Shopping(User user);
}

UserProcessor.cs

public class UserProcessor : IUserProcessor
{
  public void Shopping(User user)
  {
    Console.WriteLine("买呀,买呀,买苹果!");
  }
}

UserDecoratorProcess.cs

public class UserDecoratorProcess : IUserProcessor
{
  private IUserProcessor processor;

  public UserDecoratorProcess(IUserProcessor processor)
  {
    this.processor = processor;
  }

  public void Shopping(User user)
  {
    PreShopping();
    processor.Shopping(user);
    PostShopping();
  }

  private void PreShopping()
  {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("买东西前,判断是否注册了!");
    Console.ResetColor();
  }

  private void PostShopping()
  {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("买完东西后,写个日志文件!");
    Console.ResetColor();
  }

}

Decorator实现AOP编程。的更多相关文章

  1. 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

  2. 使用spring方式来实现aop编程

    1:什么是aop? Aspect Oriented Programming 面向切面编程 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...

  3. Spring学习笔记之四----基于Annotation的Spring AOP编程

    你能使用@Aspect annotation将某个Java类标注为Aspect,这个Aspect类里的所有公有方法都可以成为一个Advice,Spring提供了5个Annotation去将某个方法标注 ...

  4. 聊Javascript中的AOP编程

    Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...

  5. 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--AOP编程

    AOP编程在目前来说好像是大家都比较喜欢的.ASP.NET MVC中的Filter就是使用AOP实现的配置器模式.AOP在编码中的应用主要有如下几个方面: 日志记录,跟踪,优化和监控 事务的处理 持久 ...

  6. Python Decorator 和函数式编程

    看到一篇翻译不错的文章,原文链接: Python Decorator 和函数式编程

  7. struts2.1笔记03:AOP编程和拦截器概念的简介

    1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...

  8. Method Swizzling以及AOP编程:在运行时进行代码注入-备用

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

  9. Aop编程--注解与xml的实现

    一.注解方式 1.首先引入spring对于aop编程的jar支持包,spring框架没有的包请自行在网上下载. aopalliance-alpha1.jar aspectjrt.jar aspectj ...

随机推荐

  1. MYSQL获取自增ID的四种方法

    MYSQL获取自增ID的四种方法 1. select max(id) from tablename 2.SELECT LAST_INSERT_ID() 函数 LAST_INSERT_ID 是与tabl ...

  2. It matters, In the coming year ,i will stand here.

    人在安逸中会迷失自己,直至看不到远处的光亮.在一个人迷茫的时候便需要寻找认同感,于是我来到了这里.比我更加优秀的人都在默默的努力,我怎么能允许自己在原地踏步.在这一刻我似乎又看了黑夜中的一束光. 初识 ...

  3. .net 附加W3wp进程

    步骤:1.鼠标右键点击application项目中的web,找到属性 2.修改web服务器地址(如果使用localhost报错,则http://电脑IP/): 3.在本地iis中找到你部署的网站,点击 ...

  4. (BFS)poj3669-Meteor Shower

    题目地址 为判断某时刻能否走到某位置,建立shi数组,记录某位置最早t时刻就不能走.(初始化为-1)之后开始从(0,0)出发bfs,用bu数组记录走到某一位置时花费的步数,并且需要用vi数组记录是否走 ...

  5. bug report: Jump to the invalid address stated on the next line at 0x0: ???

    gdb或者vlagrind报告: ==14569== Jump to the invalid address stated on the next line ==14569== at 0x0: ??? ...

  6. 面试复习(C++)之直接插入排序

    #include <iostream> using namespace std; void Insertsort(int *a,int len) { ;j<len;j++) { in ...

  7. 使用expect脚本语言写一键发布服务(代码发布、所有服务重启)

    互联网服务有很多台服务,但是在上线的时候需要将这些服务版本都更新与个个都重启,下面的脚本语言,就是一键发布服务~ 1.在/home/weihu/deploy/ 目录下建下publish .publis ...

  8. 关于TortoiseGit使用的心得

    花了我一个晚上,终于弄明白为什么总是 push 失败的原因了!竟然是因为我用的是注册的用户名而不是邮箱名……囧死. 另外搞清楚了一个问题,就是 Git 和远程仓库交互有两种方式,即 https 方式和 ...

  9. 不使用ASP.NET中的服务器控件将如何上传文件?

    遇到文件的上传时,可能会有大部分的开发者喜欢使用服务器控件,虽然很方便,但是却不能很好的控制,不具灵活性. 现给出例子,使用html标签语言灵活的控制文件的上传. 1.html部分 <input ...

  10. Socket异步存储示例

    异步客户端存储示例: using System; using System.Net; using System.Net.Sockets; using System.Threading; using S ...