0

tomoon | 单例模式

 1 year ago
source link: https://benpaodewoniu.github.io/2022/12/20/tomoon55/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

tomoon | 单例模式 | 犀牛的博客

姑苏城外一茅屋,万树梅花月满天

单例模式的讲解请参考 单例模式

这是 RhinoGateway 的应用。

这是一个交易所模块,具体功能有 下单、获取订单状态等等。

每个交易所都有该方法,当你传入参数,其会给你返回相应的值。所以,交易所之间的方法时独立的,交易所的方法是幂等的。

如果,策略信号一来,你就重新创建对象,然后执行策略或者其他,完全是不必要的。所以,交易所的实例只需要初始化一次就好了。

这里我选择的方式是懒汉模式。不过,对于该项目而言,懒汉模式和饿汉模式没有区别,因为都会先初始化完成,然后方法调用。

关于如何初始化,请参考 tomoon | 策略模式


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK