简体   繁体   English

这四个Android类组成的模式的名称是什么?

[英]What is the name of the pattern that these four Android classes comprise?

There's a bit too much code to post here so, I'll post the github links: 这里要发布的代码太多,因此,我将发布github链接:

PhotoManager.java PhotoManager.java

PhotoTask.Java PhotoTask.Java

PhotoDecodeRunnable.java PhotoDecodeRunnable.java

PhotoDownloadRunnable.java PhotoDownloadRunnable.java

From the comments in the PhotoTask class: PhotoTask类中的注释中:

This class manages PhotoDecodeRunnable and PhotoDownloadRunnable objects. 此类管理PhotoDecodeRunnablePhotoDownloadRunnable对象。 It doesn't perform the download or decode; 它不执行下载或解码; instead, it manages persistent storage for the tasks that do the work. 相反,它管理完成任务的持久性存储。 It does this by implementing the interfaces that the download and decode classes define, and then passing itself as an argument to the constructor of a download or decode object. 为此,它实现了下载和解码类定义的接口,然后将自身作为参数传递给下载或解码对象的构造函数。 In effect, this allows PhotoTask to start on a Thread, run a download in a delegate object, then run a decode, and then start over again. 实际上,这使PhotoTask可以在线程上启动,在委托对象中运行下载,然后运行解码,然后重新开始。 This class can be pooled and reused as necessary. 可以对此类进行池化,并根据需要重用。

The comment regards PhotoTask as "manages persistent storage for the tasks". 该评论将PhotoTask视为“管理任务的持久存储”。 Is this the delegate pattern? 这是委托模式吗? I'd be appreciative of any knowledge that you have regarding these classes and, the pattern. 对于您对这些类和模式的了解,我将不胜感激。

The PhotoManager uses an Object Pool pattern, or more specifically a Thread Pool , as it creates, manages and reuses thread instances in a pool. PhotoManager在创建,管理和重用池中的线程实例时会使用对象池模式,或更具体地说是线程池。

Runnable classes in general use the Command pattern , which is way to imitate delegates without function pointers by encapsulating a method call. Runnable类通常使用Command模式 ,这是通过封装方法调用来模仿不带函数指针的委托的方法。

The PhotoTask uses multiple runnables and implements their interface. PhotoTask使用多个可运行对象并实现其接口。 It delegates its actions to the runnables, which actually looks like a Facade to me, to hide the complexity and encapsulate a specific task. 它会将其操作委派给可运行对象,对我而言实际上看起来像是“ 外观” ,以隐藏复杂性并封装特定任务。

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

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