读书笔记:ASP.NET使用代码隐藏页是否更好

资深ASP.NET开发者Stephen Walther在《ASP.NET 3.5 Unleashed》中说到:
“I’ve heard it argued that code-behind pages are superior to single-file pages because code-behind pages enable you to more cleanly separate your user interface from your application logic. The problem with this argument is that the normal justification for separating your user interface from your application logic is code reuse. Building code-behind pages really doesn’t promote code reuse. A better way to reuse application logic across multiple pages is to build separate component libraries. (Part IVof this book explores this topic.)
My personal preference is to build ASP.NET applications using single-file ASP.NET pages because this approach requires managing fewer files. However, I’ve built many applications using the code-behind model (such as some of the ASP.NET Starter Kits) without suffering dire consequences.”
 
大致意思为:
“我听到一种论调说代码隐藏页比单一页面更高级,因为代码隐藏页可以清晰地隔离用户界面与应用逻辑。该问题症结在于,用户界面与应用逻辑隔离的原因是为了代码重用。构建代码隐藏页并不会提高代码的重用。比较好的重用应用逻辑的办法是把多个页面构建成一个独立的组件库。
我个人构建ASP.NET应用程序的偏好是使用单一的ASP.NET页面,因为这一方式减少了请求管理的文件量。不过,我在不计后果的情况下也构建过许多使用了代码隐藏页模型的应用(如ASP.NET Starter Kits)。”
 
这段话在原书中第45页。
This entry was posted in .NET. Bookmark the permalink.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s