CS4720
MobileDeviceArchitecture
CS4720– MobileApplicationDevelopment
CS4720
TheWayBackTime• Whenaphonewasaphone…• Plusastory!
2
CS4720
Ohyes…thiswasaphone…
3
TheMotorolaDynaTAC 8000X• 1983• 13x1.75x3.5• 2.5pounds• $3,995• +MonthlyFee• +Payperminute
Thentherewasthebagphone…
CS4720
NokiaInventsMobilePhoneGaming!• ObviouslyI’mtalkingabouttheN-Gage!• …• Okay,rememberSnakeontheoldNokiaphones?
• Otherearlyappsinclude:basiccontactapps,Pong,andTetris
4
CS4720
Third-PartyAppsBegin• Mobilephonesstoppedbeinganovelty• Batteriesgotbetter,formfactorsimproved,coverageimproved,planswere…better…
• Thehandsetmanufacturersdidn’twanttowritealltheapplicationsforthesenewphones
• However…theydidn’twanttoopenuptheirplatform…
• Thefirstmobilewebplatformwasborn
5
CS4720
WAP• WirelessApplicationProtocol• Basicallyit’sastripped-downHTTPthatwasmeanttobebetterattransmittingovertheunreliablemobilenetwork
• WAPusedWMLinsteadofHTML–useda“card”mentality
• TwopopularWAPsites?CNNandESPN
6
CS4720
In-AppPurchasesBeforeApps• SMS…
7
CS4720
Whendiditallchange?• WiththeInternetfullofimagesandmedia…• Andotherhandhelddevicessellinglikegangbusters(GameBoy)…
• Whatchangedwithphones?• Phonesstartedrunningknownoperatingsystems(WindowsCEandLinux)
• Nowbiggerplayerswereinvolved,andhandsetmanufacturesdecidedtoopenup
8
CS4720
Andwhat’shappenedsince?• Themobilemarketisseriouslyfractured• Whodoyoudevelopfor?• HowdoyoutestforEVERYphone?• Whichmarketworksbest?• Howdoyouportyourappbetweenplatforms?• Whichtoolsdoyouuse?Canyouuse?
9
CS4720
AndNowGoogle• TheOpenHandsetAllianceisanattempttoeffectively“geteveryoneonthesamepage”
• OpenSource• FamiliarEnvironmentsandTools• SecureOS(Linuxw/appsigning)• NoRoyaltiesorDeveloperFees
10
CS4720
TheThree-TieredArchitecture
11
CS4720
TheThree-TieredArchitecture• Forawebapplication…
– Thebrowser+dynamicallygeneratedHTMListhepresentationlayer
– Middlewarefiles(function-specificPHP,JavaservletsonTomcat)containthebusinesslogic
– Thedatabaseserveristhedatalayer
12
CS4720
It'snotnewstoyou• Theconceptsofthethree-tieredarchitectureapplytomanydesignscenarios– Keepthepresentationseparatesoit'slightweight,easiertomaintain,andcanbetestedseparately
– Keepthelogicseparatesoyoucanchangethelogicasneededwithouthavingtochangethepresentationtoomuch
– KeepthedataseparatebecauseyoushouldNEVERbuildasystembasedonthecurrentdatavalues
13
CS4720
Model-View-Controller• ThisisthedefinitionofwhatMVCis• TheMVCpatternmaps:
– Identifieswhattheuserisaskingfor– Loadsaparticularresource– Displaysthepertinentinfoaboutthatresourcebacktotheuser
• ToModel,Controller,View(inthatorder)
14
CS4720
MVC
15
CS4720
MVC
16
CS4720
Controller• Theroleofthecontrollerisbasicallytrafficcop• Ittakestherequestfromtheuserand(withtheassistanceoftheserverandroutingrules)turnsitintoamethodcallofsorts
• Itfindstheappropriatemodeltoload• Itfindstheappropriateviewtoload• Itreturnsthewholethingbacktotheuser
17
CS4720
Model• Themodelistherepresentationofthedata• Thismayormaynotbedirectlylinkedtoadatabase(butoftenisinlargerapps)
• AmodelisoftentranslateddirectlyintoaDBtable,withthecolumnsasitsattributes
• Think“classdefinitionw/DBbackend”• Oftencontainsrelationshiprules(aStudenthasmanyClasses,forinstance)
18
CS4720
View• Theclosestthingtowhatyou’vebeendealingwithsofaristheview
• It’seffectivelyanHTMLtemplatethatwillbepopulatedwiththeappropriatedatafromtheloadedmodel
• ItoftenhasPHP(orwhatever)embeddedinit• AllUIcomponentsgohere
19
CS4720
PuttingitallTogether• So,ifyouwerebuildingablog,whatmightsomeofthemodelsbe?
• Whataretheresourcesthatshouldhaveaddressestothem?
• Howdotheyrelatetoeachother?
20
CS4720
Non-shockeroftheday• Weneedtoconsiderthesamethingsforamobilearchitecture
• Why?Whataddedconcernsdowehavewhenweconsidermobileapplications?– PresentationLayerconcerns– LogicLayerconcerns– DataLayerconcerns
21
CS4720
MobileArchitectures
22
• RichMobileArchitecture– Businessandsomedataservicesonthephoneitself– Goodforappsthathavetorun“offthegrid”
• ThinMobileArchitecture– Mostbusinessandalldataservicesontheserver– Goodforappsthatrequirephoneservices,butdoesrequireInternetconnectivity
• RichInternetApplication– Eschewstheuseofanyphoneresourcesotherthanabrowser
– Goodforappsthatcanrunonanythingwithabrowser
CS4720
Whicharewedoing?
23
• RichInternetApplication– Well,it'scertainlynotthisone…whynot?
• RichapporThinapp?• Dobothfollowthethree-tieredarchitecturestructure?Whyorwhynot?
CS4720
RichMobileArchitecture
24
CS4720
ThePresentationLayer• Remember:it'saphone!
– Simple=good– Peoplehavedifferentsizedfingers– Useractionscallfunctionswhichexecutefeatures;useractions!=features
– Phonescanhavevaryingamountsofpower/resources
– Phonescanbeonoroffthecellulargridatanypoint
25
CS4720
PresentationApproach• Rememberyourclienttype• Determinehowyouwillpresentdatainacoherent,unifiedmethod
• Determinehowyouwillguardagainstuntrustedinput• Ensureyouhavefactoredoutyourbusinesslogic• Determinehowyouwillpassdatabetweenlayers(i.e.howyouwillcalltheservice,howyouwillgetmoreinfoaboutabuilding,etc)
26
CS4720
TheBusinessLayer• Forthemostpart,theseareyourwebservicesandrelatedfunctionalities– Eachofyourthreewebservicesyouareusing
27
CS4720
BusinessApproach• IdentifyFEATURESthatwillexistatthislevel• Buildcomponentsthatsupportafeature'sexecution
• Hideimplementationdetailsfromthepresentationlayer
• Determineif(how)youwillcacheinformationonthedevice
• Mapoutusecases
28
CS4720
TheDataLayer• Thiswillbeyourmodulethattalkstothedatabase
• Willbeintertwinedwiththebusinesslayertosomedegree
29
CS4720
DataApproach• Foreachfeature,determinewhatdataisrequired
• BuildSQLqueriesaroundthefeatures• Ensurethatyouareusingpreparedstatementstoguardagainstincorrectdataentry(orinjection)
• Determinehowyouwillmanageconnections• Determineifyouwillbatchupcommandsintoonebigcommand
30
CS4720
YourMobileArchitecture
31
• YourApproach:• Android/iOS UIwhichcalls…
• …your “businesslogic”cope
• …thatconnectstosomedatastore(localorremote)
CS4720
TheAndroidArchitecture
32
CS4720
YourMainComponents• Activities– representasinglescreenwithaUI• Services– representsaprocessrunninginthebackground
• ContentProvider– alinkbacktothedata• BroadcastReceiver– listensforsystem-widemessagestorespondto
• Application– asetofActivitiesthatmakeupacohesiveunit
• Intent– amessagetobepassed33
CS4720
TheActivity
34
CS4720
TheIntent
35