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 ...
随机推荐
- 总结4点对学习Linux有帮助的建议(纯干货)
学习需要足够的毅力和耐心 有些人把Linux运维看作一项冗长而枯燥的工作:有些人把linux运维看作一项得力的工具.如果是前者建议还是改变一下认识,不然不建议入门这行.毕竟linux运维工作是对人的毅 ...
- 关于XE10下Indy发送字符串编码的问题
在与硬件对接的过程中,之前用D7环境下的UDPServer.Post发送的指令,硬件可正常识别并正常显示, 后来使用到XE10,重新编译之前的源码,发现所有汉字乱码显示了: 后通过对接收数据发现,实际 ...
- EasyUI表单内容整理
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- ssi项目(1)环境搭建
1.环境准备 导包(jdk1.8只支持spring4.0以上的版本) mysql驱动包 c3p0驱动包 mybatis包 spring-core.spring-aop.spring-web.sprin ...
- UILabel多种字体
UILabel *label = [[UILabel alloc] init]; label.text = @"UILabel多种字体"; UIFont *font = [UIFo ...
- wordpress 首页调用文章 不同样式的方法
<?php $count = 1; $display_categories = array(1); foreach ($display_categories as $category) { ?& ...
- 硬件抽象层:HAL
本节我们研究硬件抽象层:HALHAL,它是建立在Linux驱动之上的一套程序库.刚开始介绍了为什么要在Android中加入HAL,目的有三个,一,统一硬件的调用接口.二,解决了GPL版权问题.三,针对 ...
- js图片拖放原理(很简单,不是框架,入门基础)
<html> <meta> <script src='jquery-1.8.3.min.js'></script> <script> /* ...
- 6、Android之LayoutInflater.inflate()
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...
- 一个比较综合的项目--》>图片缓存,下拉刷新等
在办公室电脑(E:\workspace\23\Collections)