Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I deviating from MVC if I have a Backbone View without a Model?

I have a couple of Views which do not seem to have logically coherent Models. I can still try to create dummy Models for these (and properly have routers as well) but it seems unnatural to me.

So is having a Backbone View without a corresponding Model an anti-pattern?

What do the experts say on this?

like image 395
paddle42380 Avatar asked Sep 15 '11 14:09

paddle42380


3 Answers

the various components of backbone play well with each other, but there's no need for them to always go together.

i very regularly have models with no views, and views with no models. each of the pieces of a backbone app can be used in many different ways to facilitate what you need your app to do.

like image 149
Derick Bailey Avatar answered Nov 03 '22 00:11

Derick Bailey


I don't think it is specifically an anti-pattern. If all you are trying to do is encapsulate view behavior, it might make sense to write a view and attach it to an element. It might not have any business logic or persistable data... it might just be a View that encapsulates view behavior (like something that manages the state of an element based on events). In that case, there is no need for a model.

On the other hand, if you are managing a bunch of variables (persistable or not) and any type of business logic, then it makes sense to break that out into a model.

like image 34
Brian Genisio Avatar answered Nov 02 '22 23:11

Brian Genisio


If you are considering adding a dummy model or any other logic/code to make the architecture fit a pattern, that should be a red herring. The pattern should be there to assist you in designing logically well organized predictable code.

like image 22
jamesTheProgrammer Avatar answered Nov 03 '22 00:11

jamesTheProgrammer