纯数据 Objective-C 类有名称吗?

发布于 2024-09-01 22:19:38 字数 489 浏览 3 评论 0原文

这不是一个特定于代码的问题,而是一个 Objective-C 命名法问题。在 C 中,您有用于纯数据的结构。在 Enterprise Java 中,您拥有“bean”类,这些类纯粹是具有 getter 和 setter 的成员变量,但没有业务逻辑。在 Adob​​e FLEX 中,您有“值对象”。

在 Objective-C 中,是否有一个对象(当然是 N​​SObject 的后代)的正确名称,该对象仅具有 ivars 和 getters/setters(或 @property/@synthesize,如果你想变得更奇特)而没有真正的业务逻辑?

更具体的示例可能是一个简单的类,其中包含文件名、文件大小、描述和各种其他元数据的 getter 和 setter。然后,您可以将其中的一堆并轻松地将它们放入容器(NSDictionary、NSArray)中,而不需要对 C 结构进行混乱的 NSValue 包装。它也比将一堆松散类型的子 NSDictionaries 放入父容器对象中更具结构性。

This is less of a code-specific question and more of an Objective-C nomenclature question. In C you have struct for pure data. In Enterprise Java, you have "bean" classes that are purely member variables with getters and setters, but no business logic. In Adobe FLEX, you have "Value Objects".

In Objective-C, is there a proper name for an object (descended from NSObject, of course) that simply has ivars and getters/setters (or @property/@synthesize, if you want to get fancy) and no real business logic?

A more concrete example might be a simple class with getters and setters for filename, file size, description, and assorted other metadata. You could then take a bunch of these and easily throw them into a container (NSDictionary, NSArray) without the need for messy NSValue wrapping of a C struct. It is also a little more structure than putting, say, a bunch of loosely-typed child NSDictionaries into a parent container object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凤舞天涯 2024-09-08 22:19:38

不,没有特殊的名字(至少据我所知)。所有继承自 NSObject 的 Objective-C 对象都是第一类对象。当然,您可以仅使用 getter 和 setter 来实现类,但即使是合成属性也具有用于原子性和内存管理的温和“业务逻辑”。如果需要,您可以将 C 结构用于纯数据(Cocoa 中的一个示例是 NSRect),但是,正如您所说,与其他类(例如 NSDictionary)一起使用会更困难代码>.

No, there's no special name (at least as far as I know). All Objective-C objects that inherit from NSObject are first class objects. You can of course implement classes with just getters and setters, but even synthesized properties have mild "business logic" for atomicity and memory management. You can use C structs for pure data if you want (an example in Cocoa is NSRect), but then, as you say, it's more difficult to use with other classes such as NSDictionary.

梓梦 2024-09-08 22:19:38

Objective-C 中这样的类没有正式名称。人们倾向于将此类事物称为“值对象”或“纯数据对象”,但这两者都有点重载,因为它们也可以被视为引用 NSValue (或者属性列表值)和 NSData 子类。我认为后者是描述它们的最简洁的方式。

There is no official name for such a class in Objective-C. People tend to refer to such things as "value objects" or "pure data objects," but both of these are kind of overloaded since they could also be taken to refer to NSValue (or alternatively, a property list value) and NSData subclasses. The latter is the most concise way of describing them, I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文