Does adjusting an object's model property within a view controller break MVC design?

StackOverflow https://stackoverflow.com/questions/23145226

  •  05-07-2023
  •  | 
  •  

문제

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