惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MyScale Blog
MyScale Blog
U
Unit 42
M
MIT News - Artificial intelligence
小众软件
小众软件
P
Proofpoint News Feed
雷峰网
雷峰网
L
LangChain Blog
S
SegmentFault 最新的问题
腾讯CDC
F
Fortinet All Blogs
A
About on SuperTechFans
WordPress大学
WordPress大学
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
Recent Announcements
Recent Announcements
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog

博客园 - 白板

招聘.NET SE/SSE/SA -(内部推荐,上市互联网公司) 招 Senior .NET Software Engineer / Architect (ShangHai HP GDCC Regular) Road on EA & IT Governance Seriously I Enjoy Coding 企业应用层面的架构人员---持续关注SpringSide(续) 持续关注SpringSide “官方”辨析---Business Model, Business Object Model, Domain Model, Object Model, Data Model 重读《重构》之杂感 ROI of Agile Approach 读 《J2EE Without EJB》 几点WebService集成体会 界面集成 在UI层使用Domain逻辑的一些探讨 Involve me and I'll understand Look at the logic host by OO or SP from Maintaince View Tools Support for high level architecture HP's Scalable world-wide .net-connected service framework 大公司 or 小公司? Thoughtworks - Orchestration Patterns
Form Data Validation Framework?
白板 · 2006-02-11 · via 博客园 - 白板

我老土,<<Core J2EE Patterns>>这两天才开读。

在表现层中,作者写到
“The typing and constraints information is abstracted out of the model state and into a generic framework. This separates the validation of the model from the application logic in which the model is being used, thus reducing their coupling.

Model vali Form Data Validation Framework dation is performed by comparing the metadata and constraints to the model state. The metadata and constraints about the model are typically accessible from some sort of simple data store, such as a properties file. A benefit of this approach is that the system becomes more generic, because it factors the state typing and constraint information out of the application logic.

An example is to have a component or subsystem that encapsulates validation logic, such as deciding whether a string is empty, whether a certain number is within a valid range, whether a string is formatted in a particular way, and so on. When various disparate application components want to validate different aspects of a model, each component does not write its own validation code. Rather, the centralized validation mechanism is used. The centralized validation mechanism will typically be configured either programmatically, through some sort of factory, or declaratively, using configuration files.

Thus, the validation mechanism is more generic, focusing on the model state and its requirements, independent of the other parts of the application. A drawback to using this strategy is the potential reduction in efficiency and performance. Also, more generic solutions, although often powerful, are sometimes less easily understood and maintained.

An example scenario follows. An XML-based configuration file describes a variety of validations, such as "required field," "all-numeric field," and so on. Additionally, handler classes can be designated for each of these validations. Finally, a mapping links HTML form values to a specific type of validation. The code for validating a particular form field simply becomes something similar to the code snippet shown in Example 2.5.”

我取个名字叫 Form Data Validation Framework, 感觉这个东西蛮有用的(至少对我们公司这么多系统验证的逻辑老是在那里重复啊重复)。不知道.NET下面有没类似可用的东西,没有的话偶很想找时间做一个。