English 中文(简体)
MVC and Property Terminology in Objective-C
原标题:

I am having a problem with terminology I think. Is a ViewController the Controller portion of MVC? Or is it not the same thing. Is this combining the VC of MVC into one file?

Properties like .backgroundColor and .size are these the same thing as the @property and @synthesize and if so is this the same thing as an attribute? Meaning can properties and attributes be interchangeable terms in Objective-C or are they different? For example does .backgroundColor have the @properties syntax in some Cocoa class or is this the wrong way to look at it?

最佳回答

Your NSViewController subclass is definitely the controller in MVC. It controls the view and pushes data from your model classes into it.

You are also correct about .backgroundColor and all other dot-notation properties on built-in Cocoa classes. They are defined with @property and @synthesize just like classes you would write. However, there are more simple classes (actually, they are structs) used within Cocoa (such as NSSize and NSRange). When you access those fields with dot-notation (such as range.length, assuming range is an NSRange), they are not using @property or @synthesize since they are not actually Objective-C classes at all, but simple C structs.

I personally use "attribute" and "property" simultaneously in Objective-C, although other developers may disagree.

问题回答

Yes. An Objective-C class with the name "ViewController" in it s name is an Apple convention which indicates that it is a part of the Controller portion according to the Model-View-Controller paradigm.

  • Model: Your data class.

  • View: NSView, NSImageView, etc.

  • Controller: NSViewController class.

    .backgroundColor and .size are both properties.

  • The @property keyword is the declaration keyword for a property.

  • The @synthesize keyword is required to instantiate the property.





相关问题
vectors vs. vector graphics

What (if any) is the relationship between vectors used in programming languages (e.g. arrays) and vector graphics? Why do they share the term vector? Does it represent some analogous aspect of their ...

MVC and Property Terminology in Objective-C

I am having a problem with terminology I think. Is a ViewController the Controller portion of MVC? Or is it not the same thing. Is this combining the VC of MVC into one file? Properties like ....

Origin of "map" in Computer Science

In computer science, there are two definitions of the word map. The first is as an associative array, a type of container that maps values of one type to values of another type. An example of this is ...

Definition of the word "patch"

Personally, I use the word "patch" as the software equivalent of a symptomatic treatment, which makes a patch a quick-and-dirty bugfix. However, I m not sure this is correct, because I often see it is ...

What is Facet in JavaEE?

I wonder not only what is Facet but also what is Facet in physical level (as I understand it s not a separate jar, but what?)? I also wonder how can it affect my application after deploying. I ll ...

What is the meaning of "POSIX"?

What is POSIX? I have read the Wikipedia article and I read it every time I encounter the term. The fact is that I never really understood what it is. Can anyone please explain it to me by explaining ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

热门标签