paddle42380
paddle42380

Reputation: 7081

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?

Upvotes: 11

Views: 2622

Answers (3)

Brian Genisio
Brian Genisio

Reputation: 48167

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.

Upvotes: 5

jamesTheProgrammer
jamesTheProgrammer

Reputation: 1777

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.

Upvotes: 3

Derick Bailey
Derick Bailey

Reputation: 72868

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.

Upvotes: 16

Related Questions