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

推荐订阅源

月光博客
月光博客
雷峰网
雷峰网
S
SegmentFault 最新的问题
博客园 - 【当耐特】
博客园_首页
量子位
爱范儿
爱范儿
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
V
V2EX
美团技术团队
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 白板

招聘.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下面有没类似可用的东西,没有的话偶很想找时间做一个。