gpt4 book ai didi

iphone - isMemberOfClass Terminology - 为什么这样命名?

转载 作者:太空狗 更新时间:2023-10-30 03:58:50 26 4
gpt4 key购买 nike

我应该先说我来自 Java/Android 背景,这影响了我对“成员”一词的理解。也就是说,我开始学习 Objective-C,我遇到了 isMemberOfClass 方法,这个名字让我感到困惑。

我知道 isMemberOfClass 返回一个 bool 值,指示接收者是否是给定类的实例。但是,我不明白为什么在检查它是否为 INSTANCE 时调用 isMEMBER。

关于语言协议(protocol),有什么我不知道的东西可以命名吗?成员在 Objective-C 中的含义与在 Java 中的含义不同吗?

我理解成员定义的方式,它是一个类具有的东西(方法或数据),而不是一个类是(一种类型)的东西。

任何人都可以为我清除这个看似奇怪的命名约定吗?感谢您帮助新手!

最佳答案

这里的重点是 Cocoa(和它之前的 SmallTalk)不使用“成员”一词来表示“实例变量”或“函数”或任何其他使用“成员”一词的方式在 Java 或 C++ 中。有一个有用的 paper on SmallTalk来自 Harry H. Porter III,提供了一些背景信息:

As mentioned earlier, each object contains zero or more fields. The term "field" is preferable, but other languages use the term "data member" for the same concept. Smalltalk uses the term "instance variable" to mean a field, so we say, "An object contains several instance variables" to mean the same thing as "An object contains several fields" or "An object contains several data members." We will use the terms "field" and "instance variable" interchangeably.

...

In Java or C++, the programmer may add "static data members" and "static member functions" to any class. Smalltalk has a similar ability, although static data members are called "class variables" and static member functions are called "class methods". (Recall that Smalltalk calls normal fields "instance variables" and it calls normal member functions "instance methods".)

在 Cocoa 中,术语“成员”通常用于集合的上下文中(参见 [NSSet member:])。 isMemberOfClass: 提出的问题是“这个对象是这个特定类的所有实例集合的成员吗?”

这并不是说 isInstanceOfClass: 是一个不像 Cocoa 的名称。只是“成员”在这里的含义与其他一些语言中的含义不同。

关于iphone - isMemberOfClass Terminology - 为什么这样命名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18792456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com