week 23 - revision1 week 23 revision dsa. week 23 - revision2 agenda section a: multiple choice...
Post on 20-Dec-2015
217 views
TRANSCRIPT
Week 23 - Revision 2
Agenda
• Section A: Multiple choice
• Section B: Problem-oriented questions
• Topics for revision
• Review of issues arising from coursework
• Tutorial – work on section B questions
Week 23 - Revision 3
Section B
• Explaining and designing 3 tier applications based on a relational or an XML database
• Data modelling in ER models and XML structures– Location based data
• Understanding the languages used – PHP (good reading knowledge)– XML based languages (XSLT, XQuery) general understanding
• Tackling problems in design e.g.– Redundancy– Separation of concerns– State
• Alternatives in design – which technology to use – e.g. Relational v XML database, scripting languages
Week 23 - Revision 4
Topics
• Describing a web application
• XML technologies
• Redundancy
• Schema and data – separating the specific from the general
• Data- appearance separation
Week 23 - Revision 5
Describing web applications
• What the components are:– Developed resources
• html pages, scripts, data file, images
– Data sources outside the application• RSS feeds
– Infrastructure components needed• Web server, browser, plugins.
• How components interact to carry out a task ( a use case)– Use a sequence diagram– Use a narrative – tell a story
Week 23 - Revision 6
Meta-data for an active component (e.g. a PHP script)
• Admin– Who wrote it when– What work remains
• Interface– What inputs it has (parameters, data sources)– What sub-components it relies on– What it produces
• Function– An overview of what it does– Tricky parts
Week 23 - Revision 8
Sequence Diagrams
• Describe a specific sequence of actions of system components and interchanges between components
• Components represented as columns• Time goes down the page • Include only relevant components• Describes a specific ‘move’, not all possible
‘moves’• Examples
– Typical CW site
Week 23 - Revision 9
Diagrams
• Use an established convention
• Consider using a diagramming tool which supports the notation you want to use but get practice in hand drawing diagrams for the exam.
• Use different icons or symbols to distinguish different kinds of components
Week 23 - Revision 11
XML, XML Schema, XSLT, XQuery
• XML is a data representation format– e.g.track2.xml
• XML Schema is an (XML) language for defining the structure of a family of XML documents – e.g sd.xsd– Could we write a schema for XML schema?
• XSLT is an (XML) language for defining a transformation from one or more XML documents to an other
• XQuery is a (non XML) language for defining transformations, with an emphasis on quering an XML document or database of documents
Week 23 - Revision 12
SequenceDiagram name="track2"> <cast> <actor name="user" color="#CCEBD7"/> <actor name="browser" color="#CCC4D7"/> <actor name="GoogleEarth" color="#CCC477"/> <actor name="server" color="#FFEBFF"/> <actor name="showPlace.php" color="#DDFFAA"/> <actor name='weather.php' color='pink'/> <actor name="places.xml" color="red"/> <actor name='Yahoo' color='grey'/> </cast>
Week 23 - Revision 13
<trace> <action at="browser" do="render index page"/> <message from="user" to="browser" text="click on Racetracks"/> <message from="browser" to="server" text="get links.html"/> <action at="server" do="locate links.html"/> <message from="server" to="browser" text="links.html"/> <action at="browser" do="render links.html"/> <message from="user" to="browser" text="click on "Thruxton""/> <message from="browser" to="server" text="get showplace.php?name=Thruxton"/> <message from="server" to="showPlace.php" text="start (name=Thruxton)"/>…..
Week 23 - Revision 15
XSLT <xsl:variable name="nactors"> <xsl:value-of select="count(//cast/actor)"/> </xsl:variable> <xsl:variable name="width" select="100 div $nactors"/> <xsl:template match="/SequenceDiagram"> <table border="1"> <tr> <xsl:for-each select="//cast/actor"> <th width=“{$width%}" bgcolor=“{@color}"> <xsl:value-of select=“{@name}"/> </th> </xsl:for-each> </tr> <xsl:apply-templates select="trace/*"/> </table> </xsl:template>
Week 23 - Revision 16
XQuery<table border='1'><tr>{for $a in $sd/cast/actor return <th width='$width'>string($a/@name)</th>}</tr>for $x in $sd/trace/*
return <tr> { if (name($x)='action') then let $p := index-of($sd/cast/actor/@name,$x/@at ) return ( for $i in (1 to $p - 1) return <td/>, <td align='center'> if ($x/@url) then <a href='$x/@url' target='demo'>string($x/@do)</a> else string($x/@do) </td> ) else if (name($x)='message')
Week 23 - Revision 17
Redundancy
• The same text repeated a number of times causes problems in programming
• E.g. where the same code to access an RSS feed appears in 6 different but very similar scripts
• Why is this a problem?
Week 23 - Revision 18
Problems with redundancy
• If an fault was found in the RSS code, it would need fixing in many places, not just in one place
• If another place was added, the correct version of the code would need to be located
• If all place code was removed, the rss access code would be lost too.
Week 23 - Revision 19
Solution - Factoring• ‘Factoring’, normalisation..
– 42 = 2 * 3 * 7• Factor out the common text
– Into a module (function) for code• myFun( a, b)
– Into constant and variable parts• mylongurl?name=• XXX
– Into data and schema• Emp (name, number) – (‘fred,’3), (‘joe’,90)
• Recombine– At run-time, make the general script behave in a specific way by combining the constant part
with the variable part– Parameters on functions
• myFun( 10 , 20)– Concat($baseurl,$code,’.xml’)– SQL engine
• select * where name=‘joe’
Week 23 - Revision 20
Normalisation in Database
• Just the same problems
• Factor out the repeated data into a separate table and link with a common key
• To recreate the data, de-normalize using a join to get back to the combined data
Week 23 - Revision 21
Data and appearance3 Tier architecture
• Separating the base data – Data layer
• Relational tables, XML data
• from how it is used in an application– Business or application layer
• Server side scripting
• from how it appears to a user– Presentation layer
• CSS, Javascript
• Distinction is crucial but hard to make