开发者

Is there a name for a pure-data Objective-C class?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜