• 设计模式总结(3)


    设计模式总结(3)
     
    ==========================================
    singleton pattern
     
    单件模式:确保一个类只有一个实例,
    并提供一个全局访问点。
     
    线程安全:
    同步getInstance方法:
    public synchronized static Singleton getInstance();
     
    急切实例化:
    private static Singleton uniqueInstance = new Singleton();
     
    双重检查加锁
     
     
    ==========================================
    command pattern
     
    命令模式:
    command execute() client
    invoker reciever setCommand()
     
    命令模式:
    将“请求”封装成对象,以便使用不同的请求、队列
    或者日志来参数化其他对象。命令模式也支持可撤销的操作。
     
    一个命令对象通过在特定的接受者上绑定一组动作
    来封装一个请求。命令对象将对象和接受者包进对象。
    这个对象只暴露出execute()/undo() 方法。
     
     
    client: 创建一个concreteCommand,并设置接受者;
     
    invoker: 持有一个命令对象,调用其execute方法;
     
    Command:为所有命令声明了execute()/undo()方法;
     
    receiver: 进行必要的工作,实现请求;
     
    concreteCommand:定义了动作和接受者之间的绑定关系;
     
    当需要将发出请求的对象和执行请求的对象解耦的时候,
    使用命令模式。
     
    通过命令对象进行沟通,命令对象封装了接受者的一个
    或一组动作。
     
    调用者通过调用命令对象的execute() 方法发出请求,
    接受者执行动作。
     
    调用者可以接受命令对象作为参数。
     
     
    支持撤销操作。
     
    宏命令是调用多个命令对象的execute()。
     
    命令也可以实现日志和事务系统。
     
     
     
     
  • 相关阅读:
    C++中四种类型转换方式
    LeetCode——Move Zeroes
    LeetCode——Construct the Rectangle
    LeetCode——Add Digits
    LeetCode—— Invert Binary Tree
    LeetCode——Sum of Two Integers
    LeetCode——Find the Difference
    LeetCode——Maximum Depth of Binary Tree
    kafka 安装及部署
    apache kafka系列之server.properties配置文件参数说明
  • 原文地址:https://www.cnblogs.com/ihongyan/p/3797775.html
Copyright © 2020-2023  润新知