Tải bản đầy đủ - 0 (trang)
Chapter 6. Design Patterns and Standard Practices

Chapter 6. Design Patterns and Standard Practices

Tải bản đầy đủ - 0trang

methodicalapproach.Thebasicgoalistocreateagadgetthat

canbedynamicandlooselycoupledsothatitcanadaptand

extenditself.

Thischapterlistsasetofdesignpatternsandstandard

practicestohelpingadgetdevelopment.Thisprovidesa

consistentandstandardframeworkfordevelopment.Thislistis

notintendedtobecomprehensivebutratheronethatgetsyou

thinkingaboutdesignpatternswithinthecontextofgadget

development.

Thefollowingstandardpatternsandpractices,whichare

illustratedinFigure6.1,haveimportantbenefitswithregardto

gadgetdevelopment:

Maintainable

Customizable

Extensible

Figure6.1.Followingadesignpatternbenefitsthe

developerinthelongrun.



Thefollowingsectiondiscusseseachoftheseaspectsinmore

detail.



Maintainable

Havingastandarddesignpatternhelpstomaintainthegadget

andmakesiteasiertoaddnewfeatures.Afterthegadgetis

uploadedyoumightreceiveanumberofrequestsfromusersall

overtheworldforimprovements,enhancement,andnew

features.

Forexample,althoughtheMyBlogGadgetcoveredinChapter5

isfunctional,afteryoustartusingityoumightwanttoaddnew

features.Itbecomeseasiertoupgradeagadgetifyouwritethe

gadgetwithgooddevelopmentpractices.



Customizable

Agadgetmayneedtobecustomizedtomeetaspecificuser

need.Forexample,theMyBlogGadgetcanbeusedforany

existingblogs,butifyouneedtocustomizeitforaspecificblog

withauniquesetoffeatures,itistoyouradvantageifthe

gadgetiswrittenwiththepossibilityofcustomizationinmind.

Imagineagadgetthatdisplaysatrickofthedayfromablog

(www.trickofmind.com,forexample).Ithasanormalquestion

everydaybutFridays,however,whenitinsteadhasabig

puzzle.YoucantakeadvantageofthisbycreatingaTrickofthe

DayGadget,basedontheMyBloggadget,thathascustom

actionsifthedayisFridayorwhenthequestionisalongone.



Extensible

Oneofthedesirabletraitsofagadgetisextensibility.Thatway

agadgetcanbeusedtoextendexistingfunctionality.For

example,TickerCounterGadgets,whichcountdownthe

numberofdaystoaneventareverypopular,butifyoucreate

onethatcanextenditselftoaccommodateeventsinMicrosoft

Outlook,italsobecomesausefultool.

Adesignpatterngivesagenericlayoutandstructuretoa

gadget'sdevelopment,whichhelpstosolidifythegadget's

foundation.Ithelpsyoutocreatethegadgetbasedonthe



existingtemplate,whichhasallthecommonfilesand

functionalities.Italsohelpsyouunderstandeachcomponentof

thegadgetindividually.



Chapter6.DesignPatternsandStandard

Practices

"Designistheconsciousefforttoimposeameaningful

order."

—VictorPapanek

INTHISCHAPTER

DesignPatterns

ElementsofDesignPatterns

CommonAssumptions

AddingAccessability



DesignPatterns

Designpatternsrefertotriedandtestedsolutionstorecurring

problems.Standardpracticepointstothereuseofknown

methodsfordevelopingfunctionalitycommontosimilar

applications.

Althoughgadgetsarelightweightapplicationsanddon'tfollowa

completesoftwaredevelopmentlifecycle(SDLC),developinga

gadgetissimilartodevelopingsoftware.Knowledgeofexisting

patternsandpracticesandtakingastandardizedapproach

helpsalotingadgetdevelopmentandensuresasmooth

developmentprocess.

Whatisthecommonfunctionalityofaparticulartypeof

gadget?Whatfactorsingadgetdevelopmentenableyouto

extendanexistinggadget,tocustomizeagadgetaccordingto

newrequirements?Thesearesomeofthequestionsyouneed

toanswerbeforedevelopingagadget.Chapter5,"Creatinga

SimpleGadgetwithRSS/AtomFeed,"concentratedonthe

gadget'sbasicfunctionality.Thischaptertakesamore



methodicalapproach.Thebasicgoalistocreateagadgetthat

canbedynamicandlooselycoupledsothatitcanadaptand

extenditself.

Thischapterlistsasetofdesignpatternsandstandard

practicestohelpingadgetdevelopment.Thisprovidesa

consistentandstandardframeworkfordevelopment.Thislistis

notintendedtobecomprehensivebutratheronethatgetsyou

thinkingaboutdesignpatternswithinthecontextofgadget

development.

Thefollowingstandardpatternsandpractices,whichare

illustratedinFigure6.1,haveimportantbenefitswithregardto

gadgetdevelopment:

Maintainable

Customizable

Extensible

Figure6.1.Followingadesignpatternbenefitsthe

developerinthelongrun.



Thefollowingsectiondiscusseseachoftheseaspectsinmore

detail.



Maintainable

Havingastandarddesignpatternhelpstomaintainthegadget

andmakesiteasiertoaddnewfeatures.Afterthegadgetis

uploadedyoumightreceiveanumberofrequestsfromusersall

overtheworldforimprovements,enhancement,andnew

features.

Forexample,althoughtheMyBlogGadgetcoveredinChapter5

isfunctional,afteryoustartusingityoumightwanttoaddnew

features.Itbecomeseasiertoupgradeagadgetifyouwritethe

gadgetwithgooddevelopmentpractices.



Customizable

Agadgetmayneedtobecustomizedtomeetaspecificuser

need.Forexample,theMyBlogGadgetcanbeusedforany

existingblogs,butifyouneedtocustomizeitforaspecificblog

withauniquesetoffeatures,itistoyouradvantageifthe

gadgetiswrittenwiththepossibilityofcustomizationinmind.

Imagineagadgetthatdisplaysatrickofthedayfromablog

(www.trickofmind.com,forexample).Ithasanormalquestion

everydaybutFridays,however,whenitinsteadhasabig

puzzle.YoucantakeadvantageofthisbycreatingaTrickofthe

DayGadget,basedontheMyBloggadget,thathascustom

actionsifthedayisFridayorwhenthequestionisalongone.



Extensible

Oneofthedesirabletraitsofagadgetisextensibility.Thatway

agadgetcanbeusedtoextendexistingfunctionality.For

example,TickerCounterGadgets,whichcountdownthe

numberofdaystoaneventareverypopular,butifyoucreate

onethatcanextenditselftoaccommodateeventsinMicrosoft

Outlook,italsobecomesausefultool.

Adesignpatterngivesagenericlayoutandstructuretoa

gadget'sdevelopment,whichhelpstosolidifythegadget's

foundation.Ithelpsyoutocreatethegadgetbasedonthe



existingtemplate,whichhasallthecommonfilesand

functionalities.Italsohelpsyouunderstandeachcomponentof

thegadgetindividually.



ElementsofDesignPatterns

Implementationofagadgetcanbedividedintothreemain

partswithrespecttothedesignpattern(seeFigure6.2):

Layoutofthephysicalfilestructure

Reusabilityofthefunctionality

Customizeddisplayandpresentation

Figure6.2.Designpatternshelpinreusabilityofthe

gadget.



Intheprecedingchapteryoulearnedhowtocreateasimple

gadget.Inthischapterwewillextendthatgadgetandmakea

frameworkwithastandardizedversionofallthreeabove

mentionedpatterns.Thefirstisthefileanddirectorystructure.

Havingamodularfilestructureisveryimportantbecausethis

separateseachentityintoasinglefilethatcanbeindividually

modifiedwithoutaffectingthegadgetasawhole.

Thesecondimportantaspectofreusabilityisthestandard

functionalitycommontoallthegadgets.TheMyBlogGadgetis

aninformationgadget.Ifyoucreateacoretemplatethathas

allthecommonfunctionalityofaninformationgadget,itcanbe

easilyextendedtocreateanykindofinformationgadget.



Andfinallyit'simportanttoaddresstheissueofacustomized

displayandpresentation,onethatisspecificfortheactual

gadgetbeingimplemented.Althoughgadgetsuserequirementspecificimagesandpresentations,thedesignpatterncanstart

withadefaultimageandpresentation.Thismakesagadget

frameworkreadytouseimmediately.



StandardLayoutforFilesandFolders

Astandardgadgetcontainsthefollowingfiles:

AnXMLfile

HTMLfiles

JavaScriptfiles

Cascadingstylesheet(CSS)files

Images

ForconfigurationinGadgetPicker

Foruseinthegadget

Standardpracticeforthegadgetinvolvesthreeaspectsofthe

gadgetlayout:

Amodularfilestructure—Amodularpracticefora

gadgethasHTMLfileswithassociatedstylesheet(CSS)

files.ThesefileshaveJavaScriptfunctionalityforinteracting

withtheGadgetObjectModel,theInternet,andwitheach

other.HavingseparateJavaScriptfilesforeachofthemis

alsoagoodpractice.

Localeinformation—Localizationistheprocessof

adaptingthegadgettothelanguageandcultureofa

particularregion.ThelocalizationstrategyforMicrosoft

Sidebarisautomaticanddirectory-based,asareJavaScript

files.



Thismeansthatifyoucreateafolderwithanamespecific

toaparticularlocale,en-MX,forexample,andifyouputall

yourXML,HTML,CSS,andJavaScriptfilesinsidethatfolder,

thesidebarautomaticallyretrievesthefilesinthose

directorieswhenitisunderthatlocale.

Imagegrouping—Agadgethasanumberofimages

relatedtoit.Theseimagescanbedividedintostandard

gadgetconfigurationimages,aswellasimagesthatare

displayedinthegadget'sHTMLfiles.Thestandardimages

aretheicon,dragicon,andthelogo.Theseimagesare

usedtoidentifyanddescribethegadgetintheGadget

Pickerwindow.Allotherimagesaretobeusedbythe

gadgetwindows.



GadgetDirectoryandFileStructure

Let'sgothroughthegadget'scurrentdirectorystructure.The

MyBlogGadgethasasimpledirectorystructure,asshownin

Figure6.3.

Figure6.3.Simplisticlayoutandfilestructureofthe

MyBlogGadget.



Thedirectorystructureshownhereisnotmodular.All



JavaScriptfilesareinsideasinglegadget.jsfile.Theflyout

andsettingsHTMLfileshavestyleinformationembeddedin

them.Allthefilesaregroupedtogetherintherootfolderand

graphicsintheimagesfolder.TheMyBlogGadgetalsodoesnot

accommodatelocalization.So,inthischapter,we'llcreatea

standardMyBlogGadgetandnameitMyBlogStandard.The

nameofthefolderinside,whichwillhaveallthefiles,is

MyBlogStandard.Gadget.

Tofollowastandardlayoutpattern,threethingsmustbedone:

Modularizingthefilestructuresothateachfilehasitsown

associatedCSSandJavaScriptfiles

Categorizingimagesintoroot-levelconfigurationofimages

andgadgetimages

Accommodatingspecificlocaleinformationforthegadget

TheSidebarlooksforfilestoaccommodatelocalizationstarting

withspecificlocalizationfolders,andthensearchesmore

generally,alongthissequence:

1. Language–Countryfolder(forexample:en-US)

2. Languagefolder(forexample:en)

3. Therootfolder(inthiscaseMyBlogStandard.Gadget)



StandardLayout

IfyouweretomodifytheMyBlogGadgetdirectorystructure

withthelayoutofthestandardpractice,youwouldhavea

structureliketheoneinFigure6.4.

Figure6.4.Standardlayoutandfilestructurewithlocale

information.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 6. Design Patterns and Standard Practices

Tải bản đầy đủ ngay(0 tr)

×