简体   繁体   English

苹果为什么说“操作”是抽象类?

[英]Why apple says Operation is abstract class?

If swift does not have abstract class, then why apple says Operation is abstract class? 如果swift没有抽象类,那么苹果为什么说Operation是抽象类?

From the foundation documentation, operation is: 根据基础文档,操作为:

An abstract class that represents the code and data associated with a single task. 表示与单个任务关联的代码和数据的抽象类。

Also from the same documentation: 同样来自同一文档:

Because the NSOperation class is an abstract class, you do not use it directly but instead subclass or use one of the system-defined subclasses (NSInvocationOperation or NSBlockOperation) to perform the actual task. 因为NSOperation类是抽象类,所以您不直接使用它而是使用子类或使用系统定义的子类之一(NSInvocationOperation或NSBlockOperation)来执行实际任务。 Despite being abstract, the base implementation of NSOperation does include significant logic to coordinate the safe execution of your task. 尽管很抽象,但是NSOperation的基本实现确实包含了重要的逻辑,以协调任务的安全执行。 The presence of this built-in logic allows you to focus on the actual implementation of your task, rather than on the glue code needed to ensure it works correctly with other system objects. 这种内置逻辑的存在使您可以专注于任务的实际实现,而不是确保其可以与其他系统对象正常工作所需的粘合代码。

NSOperation has its concrete counterparts, for example, NSBlockOperation NSOperation有其具体对应项,例如, NSBlockOperation

The NSBlockOperation class is a concrete subclass of NSOperation that manages the concurrent execution of one or more blocks. NSBlockOperation类是NSOperation的具体子类,它管理一个或多个块的并发执行。 You can use this object to execute several blocks at once without having to create separate operation objects for each. 您可以使用该对象一次执行多个块,而不必为每个块创建单独的操作对象。 When executing more than one block, the operation itself is considered finished only when all blocks have finished executing. 当执行多个块时,仅当所有块执行完毕后,操作本身才被视为完成。

Blocks added to a block operation are dispatched with default priority to an appropriate work queue. 默认情况下,添加到块操作中的块将被调度到适当的工作队列。 The blocks themselves should not make any assumptions about the configuration of their execution environment. 块本身不应对其执行环境的配置做任何假设。

Although Objective-C does not provide abstract classes formally as other programming languages do (EG: Java) it's possible to implement them, and Apple does it in many elements of their SDKs. 尽管Objective-C并没有像其他编程语言(例如Java)那样正式地提供抽象类,但可以实现它们,而Apple在其SDK的许多元素中都可以实现。

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

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