Will i break MVC-pattern design if i choose to modify an object's model property within a view controller?

for example, ZZQuery is a model used in ZZViewController, declared as property *zQuery. I want to see if zQuery contains propertyA, and if so - mark zQuery's boolA as YES.

 if (self.zQuery.propertyA)
        {
            self.zQuery.boolA = YES;
        }

does the code above break MVC design? or am I allowed to modify zQuery without breaking design?

有帮助吗?

解决方案

In my opinion a view controller should only update the model in response to user interaction with the view. If, for example, you have a boolean in the model and the user changes a switch on the view that is tied to this boolean then the view controller can update the model to reflect the user input.

In your example the change to the model is based on "business logic", so the model shouldn't be changed by the view controller. The relationship between propertyA and boolA should be managed by the model.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top