DRY VS安全性和可维护性与MVC和视图模型 [英] DRY vs Security and Maintainability with MVC and View Models

查看:186
本文介绍了DRY VS安全性和可维护性与MVC和视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢努力干,显然它并不总是可能的。不过,我有过,似乎pretty MVC中常见的一个概念划伤我的头,谓之视图模型。

I like to strive for DRY, and obviously it's not always possible. However, I have to scratch my head over a concept that seems pretty common in MVC, that of the "View Model".

视图模型设计为只有最少信息量传递给视图,这两个安全性,可维护性和测试的担忧。我明白了。这说得通。

The View Model is designed to only pass the minimum amount of information to the view, for both security, maintainability, and testing concerns. I get that. It makes sense.

然而,从一个干的角度来看,一个视图模型被简单地重复您已经有数据。视图模型可能是暂时的,只作为DTO,但你基本上维修器材两个不同的版本,这似乎违背了DRY本金相同型号的。

However, from a DRY perspective, a View Model is simply duplicating data you already have. The View Model may be temporary, and used only as a DTO, but you're basically maintaing two different versions of the same model which seems to violate the DRY principal.

不要视图模型违反DRY?他们是一个必要之恶?难道他们做的比坏的多好?

Do View Models violate DRY? Are they a necessary evil? Do they do more good than bad?

推荐答案

这已经提出了一次又一次。它不仅是一个pretty大幅愚弄但得到的答复是主观和议论。的ViewModels是DDD的响应和持续性无知的概念。

This has been brought up time and time again. Not only is it a pretty substantial dupe but the answer is subjective and argumentative. ViewModels are a response to DDD and the concept of persistence ignorance.

要说不使用的ViewModels是坏的方式忽略Django和Rails和大多数PHP ORM / MVC框架不在乎在所有关于这些概念。你想别人告诉你所有的其他语言和框架是做错了?

To say not using ViewModels is bad means ignoring that Django and Rails and most PHP ORM/MVC frameworks don't care at all about those concepts. Do you want somebody to tell you all those other languages and frameworks are "doing it wrong?".

无论你想使用的ViewModels取决于什么风格的建筑你要去的和应用程序的目标是什么100%。

Whether or not you want to use ViewModels is 100% dependent on what architecture styles you are going for and what the goals of the application are.

这就像问是拖,并在适当的一个WebForm应用下探GridView的?取决于很多东西。

This is like asking is dragging and dropping GridViews in a WebForm app appropriate? Depends on a lot of things.

还有一个关于DRY误解,认为你在这里。从做一个WCF服务代理类违反DRY?是否包含视图模型逻辑?干的主要目标是没有重复的逻辑与有意义的目的。做一对夫妇的DTO的这个比例对象SHA preS违反了吗?

There is also a misconception about DRY that you have here. Do Proxy classes from a WCF service violate DRY? Does the ViewModel contain logic? The primary goal of DRY is to not have duplicated logic with a meaningful purpose. Do a couple of DTOs that share object shapres violate that?

限界上下文的DDD主要将使一个良好的阅读了。如果我的购物对象需要在仓库里VS电子商务网站设置不同的功能是否意味着你分享的类型?当只有共享功能总计价格(价格+税+运费)会发生什么?你创建一个基类只为因此增加的耦合?什么是时间/成本/维护权衡的是100%的干像GetTotal一个简单的方法()。是否违反干很有道理实际上降低了复杂性和维护codeBase的总成本是什么时候?

The DDD principal of bounded contexts would make for a good read too. If a ShoppingCart object needs to function differently in a warehouse vs ecommerce website setting does that mean you to share the types? What happens when the only shared functionality is totaling a price ( price + tax + shipping )? Do you create a base class just for that therefore increasing coupling? What are the tradeoffs in time/cost/maintenance for being 100% DRY for a simple method like GetTotal(). Does violating DRY when it makes sense actually decreasing the complexity and overall cost of maintaining your codebase?

我很抱歉与这么多的问题回答,但希望现在你可以看到你问的问题的细微差别和复杂性。 ;)

I'm sorry for answering with so many questions but hopefully now you can see the nuances and intricacies of the question you asked. ;)

这篇关于DRY VS安全性和可维护性与MVC和视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆