简体   繁体   English

使用Performer的这种设计模式的名称是什么?

[英]What is the name of this design pattern using Performer?

What is the name of the pattern that used Retrofit 2.0 and some other libraries? 使用Retrofit 2.0和其他一些库的模式的名称是什么?

The old version 旧版本

some manager can load data sync and async by two different methods 一些管理员可以通过两种不同的方法加载数据同步和异步

SomeClass obj = someManager.getDataSync();
SomeClass2 obj = otherManager.getBigDataSync()
SomeClass3 obj = otherManager2.getMyDataSync()

or 要么

someManager.loadData(callback)
otherManager.loadData(callback2)
otherManager2.loadData(callbak3)

Now istead uses a helper class 现在我使用助手类

New version 新版本

Performer<T> performer = someManager.getSomeData(...);

then we can execute this action sync or asyc with listener 然后我们可以使用监听器执行此动作同步或异步

T data = performer.performSync();

or 要么

performer.performAsync(callback);

This looks like Event-based Asynchronous pattern, as described here https://msdn.microsoft.com/en-us/library/wewwczdw(v=vs.110).aspx 这看起来像基于事件的异步模式,如此处所述https://msdn.microsoft.com/en-us/library/wewwczdw(v=vs.110).aspx

It is basically a concurrency pattern allowing easy use of both synchronous and asynchronous versions of methods. 它基本上是一种并发模式,允许轻松使用同步和异步版本的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM