MVC - Cocoa interface - Cocoa Design pattern book
- by Idan
So I started reading this book:
http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022
On chapter 2 it explains about the MVC design pattern and gives and example which I need some clarification to.
The simple example shows a view with the following fields:
hourlyRate, WorkHours, Standarthours , salary.
The example is devided into 3 parts :
View - contains some text fiels and a table (the table contains a list of employees' data).
Controller - comprised of NSArrayController class (contains an array of MyEmployee)
Model - MyEmployee class which describes an employee.
MyEmployee class has one method which return the salary according to the calculation logic,
and attributes in accordance with the view UI controls.
MyEmployee inherits from NSManagedObject.
Few things i'm not sure of :
1. Inside the MyEmplpyee class implemenation file, the calculation method gets the class attributes using sentence like
" [[self valueForKey:@"hourlyRate"] floatValue];" Howevern, inside the header there is no data member named hourlyRate or any of the view fields.
I'm not quite sure how does it work, and how it gets the value from the right view field. (does it have to be the same name as the field name in the view).
maybe the conncetion is made somehow using the Interface builder and was not shown in the book ?
and more important:
2. how does it seperate the view from the model ? let's say ,as the book implies might happen, I decide one day to remove one of the fields in the view.
as far as I understand, that means changing the way the salary method works in MyEmplpyee (cause we have one field less) , and removing one attribute from the same calss.
So how is that separate the View from the Model if changing one reflect on the other ?
I guess I get something wrong... Any comments ?
Thanks