最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Am I deviating from MVC if I have a Backbone View without a Model? - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Sep 15, 2011 at 16:57 daxelrod 2,5891 gold badge22 silver badges31 bronze badges asked Sep 15, 2011 at 14:40 paddle42380paddle42380 7,0817 gold badges33 silver badges40 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 16

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.

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.

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.

发布评论

评论列表(0)

  1. 暂无评论