Changes for page Thinking About Design with WebObjects
Last modified by Pascal Robert on 2012/03/09 16:04
From version 6.1
edited by Pascal Robert
on 2012/03/09 16:01
on 2012/03/09 16:01
Change comment:
There is no comment for this version
To version 12.1
edited by Pascal Robert
on 2012/03/09 16:03
on 2012/03/09 16:03
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -136,4 +136,29 @@ 136 136 137 137 == Key Value Coding and WOGNL Extensions == 138 138 139 +In order for models, views, and controllers to be independent of each other, you need to be able to access properties in a way that is independent of a model’s implementation. This is accomplished by using key-value coding. 140 + 141 +=== Keys === 142 + 143 +You specify properties of a model using a simple key, often a string. The corresponding view or controller uses the key to look up the corresponding attribute value. The “value for an attribute” construction enforces the notion that the attribute itself doesn’t necessarily contain the data—the value can be indirectly obtained or derived. 144 +Key-value coding is used to perform this lookup—it is a mechanism for accessing an object’s properties indirectly and, in certain contexts, automatically. Key-value coding works by using the names of the object’s properties—typically its instance variables or accessor methods—as keys to access the values of those properties. 145 + 146 +For example, you might obtain the name of a Department object using a name key. If the Department object either has an instance variable or method called name, then a value for the key can be returned. Similarly, you might obtain Employee attributes using the firstName, lastName, and salary keys. 147 + 148 +=== Values === 149 + 150 +All values for a particular attribute of a given entity are of the same data type. The data type of an attribute is specified in the declaration of its corresponding instance variable, the return value of its accessor method, or simply in the object model. For example, the data type of the Department object name attribute may be an String object in Java. Note that key-value coding returns only object values. 151 + 152 +The value of a to-one relationship is simply the destination object of that relationship. For example, the value of the department property of an Employee object is a Department object. 153 + 154 +The value of a to-many relationship is a collection object (an array) that contains the destination objects of that relationship. For example, the value of the employees property of Department object is a collection containing Employee objects. 155 + 156 +=== Key Paths === 157 + 158 +A key path is a string of dot-separated keys that specify a sequence of object properties to traverse. The property of the first key is determined by, and each subsequent key is evaluated relative to, the previous property. Key paths allow you to specify the properties of related objects in a way that is independent of the model implementation. Using key paths you can specify the path through an object graph, of arbitrary depth, to a specific attribute of a related object. 159 + 160 +The key-value coding mechanism implements the lookup of a value given a key path similar to key-value pairs. For example, you might access the name of a department via an Employee object using the department.name key path where department is a relationship of Employee and name is an attribute of Department. 161 + 162 +Not every relationship in a key path necessarily has a value. For example, the manager relationship can be null if the employee is the CEO. In this case, the key-value coding mechanism does not break—it simply stops traversing the path and returns an appropriate value, such as null. 163 + 139 139 == Description of the Application to be Built (blog) ==