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

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

  •  05-07-2023
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top