Documentos de Académico
Documentos de Profesional
Documentos de Cultura
- ,
Program as recipe
A program is a description of a computation
Its like a recipe
Tells out to make an output (food) From inputs (ingredients) Through a series of operations (Some of which may be other recipes)
Computation
input output
Procedures are called with their inputs And respond with their return values
Computation as transformation
input output
Computation as transformation
A mouse click into A link to follow, into An HTML file, into Colors for the pixels on the screen
Objects
We said a computers memory is ultimately implemented as binary text
In practice, that text is really a bunch of separate
Everything is an object
So from now on, everything in your computers memory is an object
Primitive (indivisible) data objects Numbers (1, 7 -3.5) Text strings (bla bla bla) Procedures Compound data objects Tables of data Lists of objects Bitmaps (contain many little color objects, one per pixel) Sounds (contain 1 number per sound sample)
Data types
Object
Procedure
Integer
Float
Computers have a taxonomy of types of data objects Every object has a type
The objects type determines what procedures it can be used with Can add numbers, but not pictures or procedures
Procedure calls
When we run a procedure/program, we
Specify one data object for each of its inputs Receive one data object as its output What if the procedure needs to output several data objects?
notations to describe what procedures to call with what arguments notation called a data flow diagram
1 + 3
and whats happening to its output Doesnt scale well to complicated programs, though this is
concat
this is a test
a test
woof
4 woof woof
prefix
woo
Chaining calls
1 + 2 4 3 this
concat
this is a
concat
is a string
this is a string
Chaining chains
this
concat
this is a
concat
is a tedious
this is a tedious
concat
example of
concat
example of chaining
chaining
to be or not
concat
to be or not to be
or not
this is a test
a test
a test
concat
a testthis is
this is
this is a
concat
is a string
this is a string
this is a
concat concat
this is a string
is a string
string
woof
woof woof
length prefix
woof
??? 5
Exceptions
woof woof
length prefix
ArgumentCountException
5
Procedures fail if theres something wrong with their inputs They signal an exceptional condition
Or more commonly: throw an exception
In this case, the problem is that there are too few arguments (inputs), so we get an argument count exception
ArgumentTypeException
The most common kind of problem with a procedure call is sending the wrong type (kind) of input to a procedure Each input needs to have the right type of data Sending something the wrong kind of input will produce an argument type exception
4 woof woof
prefix
4 woof woof
prefix
ArgumentTypeException
easy for other kinds of mistakes to trigger them In this case, we switched the order of the inputs to prefix
Prefix really wants the first argument to be a string, not a number And it isnt smart enough to realize it just needs to swap the two
arguments
though So lets use a simpler example: a procedure that calls other procedures
Inputs: the procedure and its arguments Output: the output of the call to the input procedure
Big ideas
Data consists of objects Objects come in different types
Determines what operations can be performed on it
Inputs and outputs of procedures are objects Most computation is done by chaining procedure calls Procedures need
The right number of inputs With the right types In the right order Otherwise, it generates an error called an exception
Skills to build
Look at a data flow diagram and: Understand what the type of each object is Recognize when a procedure has
An input is of the wrong type
+
+ 1 1 1 2
call +
+
+ 1 1 BadProcedureException (1 isnt a procedure) 1 2
call +
+ 1
call
+
call
1 +
call
woof woof
+ 1 2
call
3
call
9 +
prefix
14
+ 1
call
+
call
1 +
call
Analysis
Design Code and Unit test
4 Main Elements
external entity - people or organisations that send data into the system or receive data from the system
process - models what happens to the data i.e. transforms incoming data into outgoing data data store - represents permanent data that is used by the system data flow - models the actual flow of the data between the other elements
Notation
Data Flow
Process External Entity
Data Flow
Process box
Data Store
Levelled DFDs
Even a small system could have many processes and
scope of the system identifies external entities and related inputs and outputs Additional notation - system box
External entity
System box
them identifies data stores that are used by the major processes boundary of level 1 is the context diagram
8.41
8.42
Joes Yard
Joes builders suppliers has a shop and a yard. His system is entirely manual. He has a stock list on the wall of his shop, complete with prices. When a builder wants to buy supplies, he goes into the shop and picks the stock items from the list. He writes his order on a duplicate docket and pays Joe, who stamps the docket as paid. The builder takes the duplicate docket and he goes to the yard and hands it to the yard foreman. The yard foreman gets the ordered items from the yard and gives them to the builder. The builder signs the duplicate docket and leaves one copy with the foreman and takes one copy as a receipt. Every week, Joe looks around the yard to see if any of his stock is running low. He rings up the relevant suppliers and reorders stock. He records the order in his order book, which is kept in the yard. The yard foreman takes delivery of the new stock and checks it against what has been ordered. He pays for it on delivery and staples the receipt into the order book. At the end of every month, Joe goes through all the dockets and the order book and produces a financial report for the shareholders. Draw a context level DFD and a level-1 DFD for this system.
Context Diagram
Find the people who send data into the system
Often data is part of a PHYSICAL transaction When handing a bar of chocolate to a shopkeeper, you ar
t completely out of the system not data that is handled by an operator within the system.
Joes Yard
Joes builders suppliers has a shop and a yard. His system is entirely manual. He has a stock list on the wall of his shop, complete with prices. When a builder wants to buy supplies, he goes into the shop and picks the stock items from the list. He writes his order on a duplicate docket and pays Joe, who stamps the docket as paid. The builder takes the duplicate docket and he goes to the yard and hands it to the yard foreman. The yard foreman gets the ordered items from the yard and gives them to the builder. The builder signs the duplicate docket and leaves one copy with the foreman and takes one copy as a receipt. Every week, Joe looks around the yard to see if any of his stock is running low. He rings up the relevant suppliers and reorders stock. He records the order in his order book, which is kept in the yard. The yard foreman takes delivery of the new stock and checks it against what has been ordered. He pays for it on delivery and staples the receipt into the order book. At the end of every month, Joe goes through all the dockets and the order book and produces a financial report for the shareholders. Draw a context level DFD and a level-1 DFD for this system.
Context diagram
Shareholders financial report
Supply invoice
Supplier
Has (passive) Buy supplies Picks stock items Writes order Pays joe Stamps docket Takes docket to yard Hands it to foreman Gets items Gives them to builder
Builder signs docket Takes copy as receipt Looks around yard and reorders Records order in order book Foreman takes delivery checks Foreman pays supplier Staples receipt to order book Produces financial report
Joe then
Looks around yard and reorders Records order in order book
Foreman
takes delivery checks Foreman pays supplier Staples receipt to order book
Customer then
Takes docket to yard Hands it to foreman
Joe
Produces financial report
Gets items
Gives them to builder Builder signs docket Takes copy as receipt
Signed docket
Buy Supplies
20 Buy supplies Customer Docket 20.1 Docket Writes Order * Docket 20.3 Stamp Docket(signature) 20.2 Pays Joe * Payment Payment
M1
Docket
* Money
Get Items
12 get items 12.2 Foreman Signed docket 12.1 Give items to customer * required stock stock 12.3 Give copy as receipt completed docket copy Get builder signature * Signed docket builder signature Customer completed docket copy
Reorder supplies
21 Reorder supplies 21.1 Joe Supply needs Reorder from yard *
Restock
22 Restock M3 Order book Supply order 22.1 supplies Take delivery * Supply order Money Payment 22.2 Pay supplier * Supplier receipt Payment Supplier supplies stock