zoukankan      html  css  js  c++  java
  • 代理模式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace DaiLiMoShi
    {
    class XiMengQing
    {
    static void Main(string[] args)
    {
    WangPo wp = new WangPo();
    wp.makeEyesWithMan();
    wp.happyWithMan();
    Console.WriteLine("--------------------------------------");
    WangPo wpjs = new WangPo(new JiaShi());
    wpjs.makeEyesWithMan();
    wpjs.happyWithMan();
    Console.ReadKey();
    }
    }
    //定义一种类型的女人,王婆和潘金莲都属于这个类型的女人
    public interface KindWomen
    {
    //这种类型的女人能做什么事情呢?
    void makeEyesWithMan();
    void happyWithMan();
    }
    public class PanJinLian : KindWomen
    {
    public void makeEyesWithMan()
    {
    Console.WriteLine("潘金莲抛媚眼.......");
    }
    public void happyWithMan()
    {
    Console.WriteLine("潘金莲和XXXX.......");
    }
    }
    public class WangPo:KindWomen
    {
    private KindWomen kindwomen;
    //默认作为潘金莲的代理
    public WangPo()
    {
    this.kindwomen = new PanJinLian();

    }
    //她可以是KindWomen的任何一个女人的代理,只要你是这一类型
    public WangPo(KindWomen kw)
    {
    this.kindwomen = kw;

    }
    public void makeEyesWithMan()
    {
    this.kindwomen.makeEyesWithMan();
    }
    public void happyWithMan()
    {
    this.kindwomen.happyWithMan();
    }

    }
    public class JiaShi : KindWomen
    {
    public void makeEyesWithMan()
    {
    Console.WriteLine("贾氏抛媚眼.......");
    }
    public void happyWithMan()
    {
    Console.WriteLine("贾氏和XXXX.......");
    }
    }
    /*
    * 水浒里是这样写的:西门庆被潘金莲用竹竿敲了一下难道,痴迷了,
    * 被王婆看到了, 就开始撮合两人好事,王婆作为潘金莲的代理人
    * 收了不少好处费,那我们假设一下:
    * 如果没有王婆在中间牵线,这两个不要脸的能成吗?难说的很!
    */

    }

  • 相关阅读:
    zbb20181207 springboot @ConfigurationProperties使用
    zbb20181206 logback,lombok 默认日志logback配置解析
    Spring Boot (8) 全局异常处理
    Spring Boot (7) JdbcTemplate访问数据库
    Spring Boot (6) Spring Data JPA
    Spring Boot (4) 静态页面和Thymeleaf模板
    Spring Boot (3) 热部署devtools
    Spring Boot (2) Restful风格接口
    Spring Boot (1) 构建第一个Spring Boot工程
    idea使用maven搭建ssm框架实现登陆商品增删改查
  • 原文地址:https://www.cnblogs.com/lifesteven/p/3578785.html
Copyright © 2011-2022 走看看