首页 \ 问答 \ 下限与紧边之间的区别?(Difference between lower bound and tight bound?)

下限与紧边之间的区别?(Difference between lower bound and tight bound?)

参考这个答案 ,什么是Theta(紧束缚)?

欧米茄是下限,很明白,算法可能需要的最短时间。 而且我们知道Big-O是上限,意味着算法可能需要的最大时间。 但我不知道Theta。


With the reference of this answer, what is Theta (tight bound)?

Omega is lower bound, quite understood, the minimum time an algorithm may take. And we know Big-O is for upper bound, means the maximum time an algorithm may take. But I have no idea regarding the Theta.


原文:https://stackoverflow.com/questions/464078
更新时间:2023-09-29 18:09

最满意答案

Cocoa代表用于完成控制反转并减少对子类化的需求。 为单个对象拥有多个委托是完全可能的,但是当将不同类型的决策委托给不同的对象是有意义的。 一个很好的例子是WebKit的WebView ,其中有五名代表负责资源加载和导航政策的各种领域。

C#的事件委托系统,允许对象注册另一个对象以在特定事件发生时通知,最接近Cocoa提供的几个通知API。 您可能会遇到的各种API,从最高级到最低级:

  • NSNotificationCenter
  • NSDistributedNotificationCenter
  • CFNotificationCenter
  • 达尔文通知。

所有这些都是类似的,所以我只会考虑你在这种情况下使用的: NSNotificationCenter

观察员,如ClassA和ClassB,向NSNotificationCenter注册他们对通知的兴趣。 他们可以指定兴趣

  • 来自特定对象的具有特定名称的通知
  • 来自任何对象的具有特定名称的通知
  • 来自特定对象的通知。

当通知中心发布匹配的通知时,通过调用他们在通知中心注册时提供的方法来通知观察员。 该方法始终具有相同的类型:它不返回任何东西,并接受单个参数, NSNotification对象。

通常情况下,ClassC会为其头文件中的通知名称声明一个常量,例如,

extern NSString *const ClassCSomethingDidHappenNotification;

有兴趣的观察员,如ClassA和ClassB,可以注册此通知的兴趣:

[[NSNotificationCenter defaultCenter]
  addObserver:self
     selector:@selector(handleSomethingDidHappen:)
         name:ClassCSomethingDidHappenNotification                
       object:aClassCObject];

当注册一个选择器并向观察者添加一个方法来处理回调时,您还可以注册一个运行队列和块,以便在发布匹配的通知时在该队列上执行。

当与通知相关的事件发生时,ClassC将通知发布到通知中心:

[[NSNotificationCenter defaultCenter]
  postNotificationName:ClassCSomethingDidHappenNotification
                object:self];

然后,通知中心将查看观察者列表,找到与该通知相符的列表,并调用适当的方法。


Cocoa delegates are used to accomplish inversion of control and lessen the need for subclassing. It's entirely possible to have multiple delegates for a single object, but this is done when it makes sense to delegate different kinds of decisions to different objects. A great example of this is WebView from WebKit, which has five delegates responsible for areas as diverse as resource loading and navigation policy.

C#'s event–delegate system, which allows an object to register with another object to be notified when a particular event occurs, is closest to the several notification APIs available from Cocoa. The various APIs you might run across are, from highest level to lowest:

  • NSNotificationCenter
  • NSDistributedNotificationCenter
  • CFNotificationCenter
  • Darwin notifications.

All are similar in spirit, so I'll only consider the one you'd use in this case: NSNotificationCenter.

Observers, such as ClassA and ClassB, register their interest in notifications with NSNotificationCenter. They can specify an interest in

  • notifications with a specific name from a specific object
  • notifications with a specific name from any object
  • notifications from a particular object.

When a matching notification is posted to the notification center, observers are notified by invoking the method they supplied at registration time with the notification center. The method always has the same type: it returns nothing and accepts a single argument, an NSNotification object.

You would generally handle your situation by having ClassC declare a constant for the notification name in its header file, for example,

extern NSString *const ClassCSomethingDidHappenNotification;

Interested observers, such as ClassA and ClassB, can then register interest in this notification:

[[NSNotificationCenter defaultCenter]
  addObserver:self
     selector:@selector(handleSomethingDidHappen:)
         name:ClassCSomethingDidHappenNotification                
       object:aClassCObject];

Instead of registering a selector and adding a method to the observer to handle the callback, you can also now register an operation queue and a block to execute on that queue when a matching notification is posted.

When the event associated with the notification occurs, ClassC posts the notification to the notification center:

[[NSNotificationCenter defaultCenter]
  postNotificationName:ClassCSomethingDidHappenNotification
                object:self];

The notification center will then look through the list of observers, find those that match this notification, and invoke the appropriate method.

相关问答

更多
  • “控制器”侧重于所有权和Facade。 外部物体将与控制器而不是受控制器对话。 通常应该直接与UITableView对话的唯一对象是UITableViewController 。 控制器通常拥有受控对象,并且控制器应至少具有与受控对象相同的使用寿命。 “代表”侧重于行为,战略和观察员。 一个对象向其委托人请求行为指导(我应该显示这些数据吗?这是什么颜色?我可以执行此操作吗?)。 一个对象告诉它的代表什么时候有趣的事情发生了(我被感动了,我即将完成某件事情,我有一个问题。)一种特殊的代表回答了数据问题(第3行 ...
  • Cocoa代表用于完成控制反转并减少对子类化的需求。 为单个对象拥有多个委托是完全可能的,但是当将不同类型的决策委托给不同的对象是有意义的。 一个很好的例子是WebKit的WebView ,其中有五名代表负责资源加载和导航政策的各种领域。 C#的事件委托系统,允许对象注册另一个对象以在特定事件发生时通知,最接近Cocoa提供的几个通知API。 您可能会遇到的各种API,从最高级到最低级: NSNotificationCenter NSDistributedNotificationCenter CFNotif ...
  • 您避免保留代表的原因是您需要避免保留周期: A创建B A设置为B的委托... A由其所有者发布 如果B保留A,A不会被释放,因为B拥有A,因此A的dealloc永远不会被调用,导致A和B都泄漏。 你不用担心,因为它拥有B,所以在dealloc中摆脱它。 The reason that you avoid retaining delegates is that you need to avoid a retain cycle: A creates B A sets itself as B's delegate ...
  • 一个Objective-C委托是一个已经分配给delegate属性的另一个对象的对象。 要创建一个,您只需定义一个实现您感兴趣的委托方法的类,并将该类标记为实现委托协议。 例如,假设你有一个UIWebView 。 如果你想实现它的委托的webViewDidStartLoad:方法,你可以创建一个这样的类: @interface MyClass // ... @end @implementation MyClass - (void)webViewDidStartLoad ...
  • “代表”不是一些奇特的对象。 它只是一个名为delegate id类型的综合属性。 如果你想,你可以拥有任意数量的符合相同协议的属性。 然后,当你想发出回调时,你只需要解决所有问题: [self.mydelegateA doSomething]; [self.mydelegateB doSomething]; 等等 你也可以有一个你可以添加对象的NSMutableArray属性,然后使用[self.myMutableArrayOfDelegates makeObjectsPerformSelector:@ ...
  • 你在MyClassic init中调用了委托方法(dimeTuNombre :),但是委托还没有设置,所以你要么重新考虑何时调用dimeTuNombre:,要么重构MyClassic类以使得构造函数像 -(id)initWithDelegate:(id)delegate 而不仅仅是简单的init。 为了澄清,当你执行[pirr setDelegate:self]时,在当前代码中设置MainViewController.h中的委托; - 将MyClassic属性的值“委托”设置为Ma ...
  • 在Objective-C中使用代表有两个主要原因,它们略有不同: 增强框架类的基本功能。 例如,一个UITableView本身就很无聊,所以你可以给它一个委托来处理有趣的位(创建表格单元格,向段落标题添加文本,你有什么)。 这样,UITableView永远不会改变,但不同的表视图可以看起来和行为非常不同。 与依赖关系层次结构中的父对象通信。 例如,您可能会看到一个按钮,用户可能会按此按钮来执行影响其他视图的操作。 该视图必须向其父视图或视图控制器发送消息,以便它可以创建或销毁或修改其他视图。 要做到这一点, ...
  • 确保您已为UIViewForWheel手动分配了委托,并且MainMenu符合该协议UIViewForWheelProtocol 。 Ensure that you have manually assigned the delegate for UIViewForWheel, and that MainMenu conforms to that protocol UIViewForWheelProtocol.
  • 不,只有一个属性,一个由@property (retain) id delegate定义的@property (retain) id delegate ; 另一个是(有点) NSObject私有变量,它不是Objective-c意义上的属性......然后,你的.m文件中有@synthetize关键字,它扩展了属性。 另一种表示法, id告诉我,该委托应该符合某个协议。 您可以从班级访问这两个,但您只能从外部访问该属性。 此外,对于属性,还会生成一些其他内容 - 在保留(不使用ARC时) ...
  • 注意:在这里混合C#和Obj-C术语,ObjC用斜体(我希望...... ;-) 我们创建一个接口,定义用户将实现的协议方法,以扩展接受此协议作为委托的另一个类的功能: 议定书 : public interface IWorkerDelegate { void PreformAdditionalWork(); } 接受协议的类: 在此示例中存储为弱引用,因此对您指定的代理保持强引用... public class Worker { WeakReference

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。