Decorator实现AOP编程。
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编程。的更多相关文章
- 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
- 使用spring方式来实现aop编程
1:什么是aop? Aspect Oriented Programming 面向切面编程 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...
- Spring学习笔记之四----基于Annotation的Spring AOP编程
你能使用@Aspect annotation将某个Java类标注为Aspect,这个Aspect类里的所有公有方法都可以成为一个Advice,Spring提供了5个Annotation去将某个方法标注 ...
- 聊Javascript中的AOP编程
Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...
- 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--AOP编程
AOP编程在目前来说好像是大家都比较喜欢的.ASP.NET MVC中的Filter就是使用AOP实现的配置器模式.AOP在编码中的应用主要有如下几个方面: 日志记录,跟踪,优化和监控 事务的处理 持久 ...
- Python Decorator 和函数式编程
看到一篇翻译不错的文章,原文链接: Python Decorator 和函数式编程
- struts2.1笔记03:AOP编程和拦截器概念的简介
1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...
- Method Swizzling以及AOP编程:在运行时进行代码注入-备用
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
- Aop编程--注解与xml的实现
一.注解方式 1.首先引入spring对于aop编程的jar支持包,spring框架没有的包请自行在网上下载. aopalliance-alpha1.jar aspectjrt.jar aspectj ...
随机推荐
- 完美解决google无法访问
1.进入短信界面 2.菜单-设置 3.修改短信中心号码(Set the SIM's smsc number) 保存 [测试结果]:提示保存成功,但是号码没有改变,退出重新进入设置才会看到号码更新 [预 ...
- Matrix(单点移动,多点缩放)
package cn.iris.matrixapi; import android.app.Activity; import android.graphics.Matrix; import andro ...
- f(n) hdu 2582
calculate the f(n) . (3<=n<=1000000)f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gcd(n).Gcd(n)=gcd(C[n][1],C ...
- JavaScript 开发的45个经典技巧
JavaScript是一个绝冠全球的编程语言,可用于Web开发.移动应用开发(PhoneGap.Appcelerator).服务器端开发(Node.js和Wakanda)等等.JavaScript还是 ...
- 最少clock
var elClock = document.getElementById("clock");var getTime = function(){ var _ = ['00','01 ...
- C++小项目:directx11图形程序(一):主框架
最近在学习DIRECTX11,在学习过程中编写了一个程序,到现在发现这个程序也有几行代码了,结构还算整齐,就想把这个程序分享出来,其中涉及到了C++程序的架构,windows窗口程序编写,和Direc ...
- 硬件抽象层:HAL
本节我们研究硬件抽象层:HALHAL,它是建立在Linux驱动之上的一套程序库.刚开始介绍了为什么要在Android中加入HAL,目的有三个,一,统一硬件的调用接口.二,解决了GPL版权问题.三,针对 ...
- C#如何获取项目中的其他文件夹的路径
//一般用string p=AppDomain.CurrentDomain.BaseDirectory+"\\其他"; //其它的还有 string str1 =Process.G ...
- The last packet successfully received from the server was 2,926,157 milliseconds ago. The last packet sent successfully to the server was 2,926,158 milliseconds ago. is longer than the server configured value of 'wait_timeout'. 解决办法
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully rec ...
- 横向滑动的GridView
思路: GridView行数设置为一行,外面套一个HorizontalScrollView,代码中设置GridView宽度 xml代码 <HorizontalScrollView android ...