Download presentation
Presentation is loading. Please wait.
Published byPenelope Welch Modified over 9 years ago
1
22 Nov 1.Comments on HW3 2.Java I/O – Exception handling 3.Inversion 4.JSD
2
Pascal identifier
3
Errors in Pascal Identifier
4
A compiler for INTEGERs What do you think about it?
5
INTEGER
6
Possible errors 1.Integer does not start with a sign or digit 2.Sign followed by non-digit 3.At least one digit does not follow the sign of a signed INTEGER 4.Non-digit follows 1 st digit of an INTEGER
7
Errors in INTEGER
8
Design for Human Error Base data structure that allows for human errors on correct data structure –Allows intelligible messages to explain error in terms of a deviation from the known structure –Data structure to accommodate errors should contain all possible errors Cognitive principle: –We make sense of the unknown / unrecognizable in reference to what we know / recognize
9
A note on Java Text I/O HelloFileRead2 HelloFileRead2a If a checked (задержанный) exception throws an exception, you must either catch it or else declare in the method header that the exception is thrown. Scanner methods catch an exception generated for an empty file
10
Structure Clashes: Modified Net Movement Problem Suppose the input file is blocked, with each block containing a record count followed by a number of records.
11
Modified Net Movement Problem: The essence of the difficulty The program must have an operation that is executed once per block and an operation that is executed once per group So there must be both a block component and a group component But we cannot have a single program structure with process block and process group components. We have a boundary clash--the boundaries of blocks are not synchronized with the boundaries of groups.
12
Solution to Boundary Clash: Decomposition
13
Input, intermediate and report files, together with their correspondences
14
Comments on JSP Solution Correctness –PA and PB can be designed using JSP. The programs we obtain are distinct. –A serial file forms a boundary between any pair of programs. We don't have to think "dynamically". For example, we don't need to ask, "What if a group extends over several blocks?" or "What if a group has no data records?“ – We know our programs are correct, because we can think in terms of static data structures Inefficient –By introducing an intermediate file, we have roughly doubled the execution time (in comparison with a program that produced a report without an intermediate file). –We will learn a little later how to optimize our design by a simple program transformation, program inversion.
15
General Solution for Structural Clashes The resolution of the structure clash is effected by decomposing the program P into two programs, PA and PB as shown below:
16
Correspondences between A, I, X The data structures of the serial input file, A, the intermediate file, I, and the output file, X are shown below: There is no structure clash between A and I, so the structure of PA can be constructed without difficulty; the same is true of I and X and PB. Whereas in general, the description of a file as an iteration of records is rarely sufficient-- though always true--in designing a program, in the case of resolving a structure clash, this description is invaluable. The intermediate file, I, contains the largest component common to both A and X--an idea analogous to the "greatest common divisor" of two integers.
17
Analysis of PA and PB Program decomposition allows us to focus on a correct analysis of PA and PB. The processing for the system diagram can be accomplished in a number of ways: 1.Batch processing 2.Parallel processing (co-routines) 3.Inversion (quasi-parallel)
18
Processing of PA and PB using (a) batch processing, (b) parallel processing and (c,d) program inversion (a) (b) (c) (d)
19
Program Inversion (инверсия программ) Program inversion is a purely mechanical transformation of the independent programs, PA and PB, into a main program and subroutine The subroutine has a single ENTRY point and stores its return address within its state vector so that it is resumable. –3 states of the subroutine: (i) open the file for rading/writing; (ii) process a record; (iii) close file
20
Concept of state vector (вектор состояния) A program consists of: 1.the program text 2.local variables 3.text pointer to next instruction to be executed state vector
21
Program Inversion Significance of Inversion Uses of inversion
22
The roots of Object-based analysis in Jackson’s entities When item transactions are sorted by item # into groups, we recognize each item as an entity (or object). To produce a report showing net movement of each item, we Must process each item group as an iteration of transaction records. It is wrong to Process the file as a selection of records as below:
23
Jackson System Development (JSD) Ideas underlying JSD 1.The real-world as modeled: a simulation (analogical model) 2.Each entity is JSD is object. JSD is object based 3.System is modeled as a network of communicating sequential processes 4.JSD specification is in principle executable, and can be transformed into executable code (using inversion). JSD method consists of 6 steps: (Student Loan System)Student Loan System 1.Entity / ActionsEntity / Actions 2.Entity StructureEntity Structure 3Initial Model and System DiagramInitial Model System Diagram 4FunctionFunction 5.System Timing 6ImplementationImplementation
24
Student Loan System (Ñèñòåì äëÿ обработка студенческéõ заемîâ) A university gives loans to students. Before getting a loan, there is an evaluation process after which agreement is always reached. A TE transaction records each step of the evaluation process, and a TA transaction records the overall loan agreement. A student can take any number of loans, but only one can be active at any time. Each loan is initiated by a TI transaction. Then, the student repays the loan with a series of repayments. Each repayment transaction is recorded by a TR transaction. Finally, a loan is terminated by a TT transaction. Two output functions are desired: (1) an inquiry function that prints out the loan balance for any student, and (2) a repayment acknowledgment sent to each student after payment is received by the university.
25
Entity/action step Characteristics of entities and actions Make candidate list of entities and actionscandidate list Finalize list of entities and actionslist of entities and actions
26
Student Loan System Consider the following description of a student loan system: A university gives loans to students. Before getting a loan, there is an evaluation process after which agreement is always reached. A TE transaction records each step of the evaluation process, and a TA transaction records the overall loan agreement. A student can take any number of loans, but only one can be active at any time. Each loan is initiated by a TI transaction. Then, the student repays the loan with a series of repayments. Each repayment transaction is recorded by a TR transaction. Finally, a loan is terminated by a TT transaction. Two output functions are desired: (1) an inquiry function that prints out the loan balance for any student, and (2) a repayment acknowledgment sent to each student after the university receives payment.
27
Entity Structure Diagram
28
Modeling real-world entity as process stream
29
System diagram Network of communicating sequential processes
30
Using JSP to Implement Functions
31
System Implementation using Inversion
32
Implementation of Scheduler using JSP
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.