版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、譯文一:一種新的網絡應用程序開發(fā)框架mvc* luo guangchun, the ph.d. of uest of china; wang yanhua, the master of the uest of china; lu xianliang, the professor of uest of china, advisor of ph.d.; han hong, the ph.d. of uest of china摘要 mvc(model/view/controller)的設計模式出現在在smalltalk-80,并在軟件的設計中廣泛應用。本文介紹一種基于mvc框架的的新網絡應用程序。這
2、種框架把實施邏輯與表現形式獨立開來。它也提高了系統的可維護性,可擴展性以及使用模塊數據庫備案、模板數據庫,通訊對象和緩沖隊列的性能。關鍵詞:mvc、設計模式、網絡應用程序1.簡介 網絡應用系統是一個基于b(rowser)/ s(erver)模型應用系統。它利用多種動態(tài)網頁開發(fā)技術。目前,軟件設計的主題之一是網絡應用開發(fā)模式和工具的。它們直接影響系統的幾個關鍵因素,比如可維護性、可擴展性、穩(wěn)定性和安全性。本文中,基于mvc1的網絡應用程序的設計模式是為解決這兩類因素擴展性和可維護性這些不易處理的問題。把mvc設計模式引入網絡應用程序開發(fā),執(zhí)行邏輯可以獨立于系統的表現形式。 mvc由三種對象組成。
3、1)模型:是應用對象,2)視圖:是它的屏幕的顯示,3)控制器:定義用戶界面并對輸入的信息做出響應。在出現mvc之前,用戶界面的設計傾向于把這些東西做在一起。然而,mvc獨立了它們,增加系統的靈活性和可重用性。mvc把視圖和模型獨立開來,在它們之間建立了“subscribe/notify”協議。一個視圖必須確保其正確反映模型的狀態(tài)。每當模型的數據發(fā)生改變,視圖會得到相應的通知。作為回應,每個視圖都會有更新自身的機會。這個方法可以讓你附上一個模型的多個視圖以便提供不同的報告。你也可以不改變原模型同時創(chuàng)建新的視圖。2.背景和存在的問題 雖然mvc的設計模式已經在smalltalk-80中提出了,并廣
4、泛應用于軟件設計,介紹它到網頁應用程序開發(fā)卻仍很困難的。主要由于以下兩個因素:1)首先,很難獨立 來自html的編程語言。早期的cgi程序使用字符串輸出創(chuàng)造了html內容。默認的,將html文本分成幾份,然后把他們嵌入到cgi程序中。腳本語言出現后,變成了腳本語言編寫的程序嵌入到html文本中。然而,這兩種方法有一個共同的不足,使他們不能完全獨立于html文本。因此,這兩種方法使采用mvc分離三層模式十分難以實現。2)第二,腳本語言的功能太弱。他們缺乏一些必要的技術支持來采用mvc的設計模式,如消息機制和事件回應機制。直到jsp model2版,這種情況并沒有受到任何改善。依靠強大的java語
5、言功能,jsp model24某種程度上實行mvc設計理念。圖 1顯示了mvc的機制:模型(數據層):它是封裝到企業(yè)javabean。視圖(表示層):jsp負責的網頁方式,如報告的格式,分頁等??刂破?控制層):servlet受到網頁上的用戶的輸入并執(zhí)行有關的操作(呼叫相應的ejb組件),給出了相關視圖,所以jsp會呈現這些結果。 jsp model2機制主要滿足了開發(fā)商對要求web應用邏輯和用戶界面獨立的需求。但制仍然存在某些限,例如,盡管jsp model2已經實施采用mvc設計模式的基本理念,三個層次之間的相互關系(servlet,java bean/ ejb和jsp)仍然封閉。特別是,
6、就servlet當控制器,不僅控制選擇同時響應模型的模塊,還負責對處理jsp轉移數據提供模塊。因為這一過程,servlet本身已實現非常復雜的執(zhí)行邏輯,對于體系的發(fā)展和維護這是正是一個棘手的問題。因此,在下面的網絡應用系統框架,我們會進一步劃分出功能的控制器。3.解決方案 圖2中顯示,這一系統框架包含三個內核控制對象/類(syscontroller, model center, and lpm(logical page module) center)和它們的核心數據庫(system description database, model database, and lpm database)。
7、這三個控制對象/類根據原始的控制器劃分。通過這些控制對象/類和數據庫,下文將解釋部分的設計思想和該系統框架的實現機制。 首先,我們考慮syscontroller和系統的描述數據庫。他們負責接收用戶的要求和根據這些請求搜索有關的執(zhí)行邏輯。系統描述數據庫可以是一個xml2文件或一套xml文件。這個數據庫描述了不同的執(zhí)行邏輯與不同的用戶請求。執(zhí)行邏輯主要包括互動模式、數據來源與異常處理等,這些組織在一個樹形結構中。而syscontroller可以搜索系統描述數據庫。它結合了用戶的要求和來自數據的執(zhí)行邏輯,然后把它們交給傳輸器來封裝。syscontroller有兩種方法搜索數據庫。 其一是使用dom對
8、象(document object model)3。當應用程序系統開機,這樣需要dom解析器分析整個數據庫備案后載入內存。數據庫將保留在內存中的dom樹結構。另一種是使用sax(simple api for xml)接口。兩者有各自的優(yōu)缺點。使用dom可以實現結構搜索。它可以在大型數據庫上使用,但是會暫用更多的系統資源。而sax接口以高效率和更少的系統資源占用率著稱。唯一的缺點是它獲得信息比dom難。 其次,我們考慮模型中心和模型數據庫。該層通過調用給定模塊完成定義執(zhí)行邏輯。模型數據庫包括大量的對象和模塊。這些對象和模塊根據特定的執(zhí)行邏輯封裝響應方法。當模式中心接收到的執(zhí)行消息,它根據封裝在信
9、息里的執(zhí)行邏輯選擇合適的對象或模塊。然后按照給定的數據格式封裝模塊,冰傳輸給lpm中心。此外,每個對象或模塊只需要關心如何實現給定的事務的邏輯以及如何獲得必要的數據而不提交這些數據。 最后,我們研究一下lpm中心和lpm數據庫。lpm是實施描述的某一種數據類型的項目集合,它可以當成是一個或一組磁盤文件。在另一方面,有一個網頁可有一個邏輯頁或多條邏輯頁。一個lpm的功能是很簡單的:它只需要在沒有被得到執(zhí)行邏輯和原數據內容的情況下給定數據類型。因此事實上,lpm是作為標簽庫(jsp)或數據捆綁(.net)而開發(fā)的。此外,這種類型的服務器腳本可以很容易由客戶開發(fā)人員在ui(user interfac
10、e)設計階段理解,what-you-see-is-what-you-get(所見即所得)工具也很容易開發(fā)。在這部分,lpm中心從模型中心收到數據。它根據給定數據類型和執(zhí)行邏輯選擇適當的邏輯頁模塊,然后封裝邏輯頁的輸出模塊到http響應并將發(fā)布到客戶端。注意到這3個控制對象,除了syscontroller,另外兩個不是直接進入自己的核心數據庫。例如,模式中心不直接從模型數據庫調用對象或模塊。它實現了通過modelfactory的存取。(過程見圖2) 通過分析系統框架,可以看出整個系統完全符合mvc設計模式。在在系統的開發(fā)時期各部分的開發(fā)者三者冰不具有相互的干涉。當系統框架已確定,各部分驚人的發(fā)現
11、開發(fā)的相似。在過去這對網絡應用程序的開發(fā)來說是不可能的。因為我們已經把控制器分為3個部分,mvc三層(模型/視圖/控制器)的聯系變得更加寬松。所以它可以明顯提高整個系統的可擴充性。在下一節(jié),我們將向你展示一個簡單的例子去解釋如何在三層mvc模式的過程通過增加中間執(zhí)行步驟擴大系統框架。4.相關問題 檢查目前的網絡應用程序設計模式(如cgi,jsp model2等等),我們可以獲得初步結果:mvc模式是一個優(yōu)于其他系統邏輯框架的網站應用系統開發(fā)模式,它平衡了合作開發(fā)、系統的可擴展性和可維護性。這主要由于舊設計模式對系統邏輯框架的獨立性的不足之處。例如,在通過cgi開發(fā)的網頁系統中,cgi程序不僅需
12、要處理執(zhí)行邏輯,同時也負責系統報告的格式。因此,它要求開發(fā)者有很強的編程能力(他們必須非常熟悉執(zhí)行規(guī)劃和界面設計)。此外,它甚至會使系統的邏輯層次混亂。最后,混沌編碼會帶來一系列的問題。使用服務器腳本語言(如asp,php等等)實現的網頁應用系統也不符合要求。其原因是,這些腳本語言都有天生的缺陷(例如,他們卻沒有有好的對象支持和事件響應機制等);他們不能令人滿意地縮短網絡應用系統的執(zhí)行邏輯。由此jsp model2的不足已在上文描述過了,所以沒有這個必要在這贅述了。5.結論 從上述對系統框圖的分析,我們可以做一個結論。改進后的mvc設計模式框架比傳統方法有更清楚的結構,每個模塊間的聯系甚少。框
13、架解決是一個大問題,曾困惑很多網絡開發(fā)者。它將執(zhí)行邏輯從表現模式獨立出來,實施并行進行發(fā)展。此外,利用模型數據庫和lpm數據庫,這個更系統的靈活性、可維護性和可擴充性得到了顯著提高。本篇討論的框架已經在uest網絡應用系統上得以實施()。參考文獻1 erich gamma. design patterns. u.s. addison-wesley pub co.2 didier martin. professional xml. u.k. wrox press.3 stephen t. mohr. designing distributed applications with xml, asp
14、, ie5,ldap & msmq. u.k. wrox press.4 sun microsystems inc. javatm servlet 2.3 and javaserver pagestm 1.2 spec fications.5 sun microsystems inc. javaserver pagestm standard tag library specification原文一:a novel web application framedeveloped by mvcluo guangchun wangyanhua lu xianliang hanhong* luo
15、 guangchun, the ph.d. of uest of china; wang yanhua, the master of the uest of china; lu xianliang, the professor of uest of china, advisor of ph.d.; han hong, the ph.d. of uest of china(information center of uest of china, chengdu, china 610054)abstractthe mvc (model/view/controller) design pattern
16、 was developed in smalltalk-80 and widely used in software design. this paper introduces a novel web application frame based on mvc. this frame separates the transaction logic from the presentation format. it also improves the system maintainability, scalability and performance by using the module d
17、atabase, template database, messaging object and buffer queue.key words: mvc, design pattern, web application1. introduction web application system is a transaction system based on b (rowser)/s(erver) model. it exploits many kinds of dynamic web developing technologies. at present, web application d
18、eveloping patterns and tools are one of the topics of the software design. they directly influence several key factors such as maintainability, scalability, stability and the security. in this paper, the purpose of mvc1-based web application design pattern is to resolve the two factors maintainabili
19、ty and scalability, which are the stubborn problems in the web application development. by introducing the mvc design pattern into the web application development, the implementation of system transaction logic can be separated from the system presentation.mvc consists of three kinds of objects. 1)
20、the model: is the application object, 2) the view: is its screen presentation, 3) the controller: defines the way the user interface reacts to user input. before mvc, user interface designs tended to lump these objects together. however, mvc decouples them to increase the flexibility and reuse. mvc
21、decouples views and models by establishing a “subscribe/notify” protocol between them. a view must ensure that its appearance reflects the state of the model correctly. whenever the models data changes, the model notifies views that depend on it. in response, each view gets an opportunity to update
22、itself. this approach lets you attach multiple views to a model to provide different presentations. you can also create new views for a model without rewriting it.2. background and problems even though the mvc design pattern was already put forward in smalltalk-80 and widely used in software design,
23、 it is difficult to introduce it into the web application development. it was mainly due to the following two factors: 1) first, it was difficult to separate the programming language from html. early cgi programs created the html content by using character string output. in nature, it divided the ht
24、ml content into several portions, and then inserted them into the cgi programs. after the appearance of script languages, the way changed to insert the programs written by script languages into html content. however, these two ways had a common deficiency that they could not separate the programs fr
25、om the html content absolutely. therefore, it is very difficult to implement the mvc detached three-layer pattern based on these two ways. 2) second, functions of the script languages are less weak. they lack some necessary technologies to support the mvc design pattern, such as message mechanism an
26、d event response mechanism. this situation did not get any improvement until the release of the jsp model 24. depending on the powerful functions of java language, the jsp model 2 implements the mvc design idea to some extent. figure 1 shows the mechanism: model (the data layer): it is encapsulated
27、into the enterprise javabean. view (the presentation layer): jsp is responsible for the presentation of pages, such as the presentation format, paging, etc. controller (the control layer): servlet receives the user input in pages and executes the relevant transaction (calling the corresponding ejb m
28、odules), then gives the results to the relevant view, so jsp can present these results. this mechanism of jsp model 2 basically meets the developers requirements to detach the web application transaction logic from the user interface. but some limits still exist. for example, although jsp model 2 ha
29、s implemented the basic idea of the mvc design pattern, the relationship of these three layers (servlet, javabean/ejb and jsp) is still close. especially the servlet, which acts as the controller, not only controls the selection and call of models modules, but also is responsible for transferring da
30、ta provided by modules to the corresponding jsp to handle. because of this process, servlet has to implement very complicated transaction logic by itself, which is a tough problem for the system development and maintenance. thus, in the following web application system frame, we will further divide
31、the functions of the controller.3. solution as show in figure 2, this system frame contains three kernel control objects/classes (syscontroller, model center, and lpm (logical page module) center) and their own kernel database (system description database, model database, and lpm database). these th
32、ree control objects/classes are divided from the raw controller. using these control objects/classes and databases, the following parts of this paper will explain the design idea and implementation mechanism of this system frame. firstly, we consider the syscontroller and the system description data
33、base. they are responsible for receiving the user requests and searching the relevant transaction logic according to these requests. the system description database can be a xml2 file or a set of xml files. this database describes the different transaction logic related to different user requests on
34、e by one. the transaction logics mainly include the interactive mode, data sources, and error handling, etc. they are organized in a tree structure. the syscontroller searches the system description database. it combines the user requests and the transaction logic searched out from the database, and
35、 then delivers them to messenger to encapsulate. there are two ways for syscontroller to search the database. one uses the dom (document object model) object3. when the application system boots, this way requires the whole database to be loaded into ram after analyzed by the dom parser. the database
36、 resides in the ram in a dom tree structure. the other one uses sax (simple api for xml) interface. both of them have their own advantages and disadvantages. using dom can implement structural search. it can achieve the efficiency in the case of larger database, but it also costs more system resourc
37、es. the sax interface is famous for its high efficiency and less system resources requirements. the only disadvantage is that it obtains some information less conveniently than the dom does. secondly, we consider the model center and model database.this layer completes the defined transaction logic
38、by calling the given module. model database contains a mass of objects and modules. these objects and modules encapsulate the responding methods relative to specific transaction logic. when model center receives the transaction messages from messenger, it selects suitable objects or modules accordin
39、g to the different transaction logic encapsulated in the message. then it encapsulated the handled data in given format and delivers them to the lpm center. furthermore, each object or module only needs to concern how to implement the given transaction logic and how to obtain the necessary data with
40、out concerning the presentation of these data. lastly, we concern the lpm center and lpm database. lpm is a set of programs to implement the presentation for a certain data type. it can correspond to a disk file or a set of disk files. on the other hand, a certain web page can contain one logical pa
41、ge or multiple logical pages. to a lpm, its function is very simple: it only need to present the given data type without being notified any transaction logic and without concerning the source and content of the data. thus, in the practical development, the lpm is developed by such technologies as la
42、bel library (jsp) or data binding (.net). furthermore, this type of server scripts can be easily understood by the client developers during the ui (user interface) design period and can be developed by some what-you-see-is-what-you-get (wysiwyg) tools. in this portion, lpm center receives the data f
43、rom the model center. it selects the suitable logical page module according to the given data type and transaction logic, then it encapsulates the output of logical page module into http response and sends the response to the client. note that among these three control objects, except syscontroller,
44、the other two do not directly access the their own kernel databases. for example, model center does not directly call the objects or modules in the model database. it implements the access through the modelfactory class instead. (showed in figure 2) according to the analysis of this system frame, we
45、 can see that the whole system perfectly conforms to the mvc design pattern. during the system development period, there is no distinct interactive relationship among the developers in each part. as long as the system frame is established, the development of each part can be preceded in parallel. it
46、 is impossible for the web application developers to use this approach in the past. because we have divided the controller into three parts, the couplings of mvc three layers (model/view/controller) become looser than ever. so it can improve the scalability of the whole system significantly. in the
47、following section, we will show you a simple example to explain how to expand the system frame by adding intermediate transaction processes among the three-layer mvc pattern.4. relative problems examining the present web application design patterns (such as cgi, jsp model 2, etc.), we can gain an el
48、ementary result: web application system developed by mvc pattern excels the one developed by other patterns at the system logical frame, parallel cooperating development, system scalability and maintainability. it is mainly due to the deficiencies of the old design patterns on system logical frame p
49、artition. for example, in web systems developed by cgi, the cgi programs not only need to process the transaction logic, but also are responsible for the system presentation format. therefore, it requires the developers to have very powerful programming ability (they have to be very familiar both with the transaction programming and the interface designing). in addition, it even makes the system logic and hierarchy chaotic. at
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 測繪管理與法律法規(guī)-注冊測繪師《測繪管理與法律法規(guī)》名師預測卷1
- 課題申報參考:跨學科主題教學的價值、困境及出路研究
- 科技產品創(chuàng)新與安全生產的平衡
- 讀書助力職業(yè)發(fā)展-職場類書籍閱讀推廣方案
- 二零二四年幼兒早教中心品牌經營許可及資產轉讓合同3篇
- 2025年貨運飛機保險合同
- 救生員勞務合同
- 2025年人教版(2024)九年級歷史上冊月考試卷含答案
- 2025年湘教版高三歷史下冊階段測試試卷含答案
- 2025年湘教版選修3歷史上冊階段測試試卷含答案
- 中央2025年國務院發(fā)展研究中心有關直屬事業(yè)單位招聘19人筆試歷年參考題庫附帶答案詳解
- 2024年09月北京中信銀行北京分行社會招考(917)筆試歷年參考題庫附帶答案詳解
- 外呼合作協議
- 小學二年級100以內進退位加減法800道題
- 保險公司2025年工作總結與2025年工作計劃
- 2024年公司領導在新年動員會上的講話樣本(3篇)
- 眼科護理進修專題匯報
- 介入手術室感染控制管理
- 2024北京初三(上)期末英語匯編:材料作文
- 2024年大型風力發(fā)電項目EPC總承包合同
- 禮儀服務合同三篇
評論
0/150
提交評論