资源描述:
《ajax in action the page as an application》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、iTePub.Net-CollectThepageasanapplicationThischaptercovers■Organizingcomplexuserinterfacecode■UsingtheModel-View-ControllerpatternwithJavaScript■Separatingpresentationfromlogicformaintainablecode■Creatingaflexibleevent-handlingmode■Generatingtheuserinterfacedirectlyfromyourbusinessobject
2、s119LicensedtojonathanzhengiTePub.Net-Collect120CHAPTER4ThepageasanapplicationInchapters1and2wecoveredthebasicprinciplesofAjax,frombothausabilityandatechnologyperspective.Inchapter3wetouchedonthenotionofcreatingmaintainablecodethroughrefactoringanddesignpatterns.Inth
3、eexamplesthatwe’velookedatsofar,thismayhaveseemedlikeoverkill,butasweexplorethesubjectofAjaxprogramminginmoredepth,theywillprovethemselvestobeindispensabletools.Inthischapterandthenext,wediscussthedetailsofbuildingalarger,scal-ableAjaxclient,andthearchitecturalprinciplesneededtomakeitwo
4、rk.Thischapterlooksatthecodingoftheclientitself,drawingheavilyontheModel-View-Controller(MVC)patternthatwediscussedinchapter3.We’llalsoencoun-tertheObserverandothersmallerpatternsalongtheway.Chapter5willlookattherelationshipbetweentheclientandtheserver.4.1AdifferentkindofMVCInchapter3,w
5、epresentedanexampleofrefactoringasimplegarmentstoreapplicationtoconformtotheMVCpattern.ThisisthecontextinwhichmostwebdeveloperswillhavecomeacrossMVCbefore,withtheModelbeingthedomainmodelontheserver,theViewthegeneratedcontentsenttotheclient,andtheControlleraservletorsetofpagesdefiningthe
6、workflowoftheapplication.However,MVChaditsoriginsindesktopapplicationdevelopment,andthereareseveralotherplacesinanAjaxapplicationwhereitcanserveuswelltoo.Let’shavealookatthemnow.4.1.1RepeatingthepatternatdifferentscalesTheclassicwebMVCmodeldescribestheentireapplicationincoarse-grainedde
7、tail.TheentiregenerateddatastreamistheView.TheentireCGIorservletlayeristheController,andsoon.Indesktopapplicationdevelopment,MVCpatternsareoftenappliedatamuchfinerscale,too.SomethingassimpleasapushbuttonwidgetcanuseMVC:■Theinternalrepresentationofstates—pressed,unpressed,inacti