$30 off During Our Annual Pro Sale. View Details »

CSE564 Lecture 03

CSE564 Lecture 03

Software Design
Refinement
(202101)

Javier Gonzalez-Sanchez
PRO

September 03, 2020
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSE 564
    Software Design
    Lecture 03: Refinement
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    PERALTA 230U
    Office Hours: By appointment

    View Slide

  2. jgs
    Previously

    View Slide

  3. jgs
    00000011
    Timeline
    1971 Wirth

    View Slide

  4. jgs
    00000011
    Stepwise Refinement
    Complete
    Task
    Subtask 1
    Subtask 1.a Subtask 1.b
    Subtask 2
    Subtask 2.a Subtask 2.b Subtask 2.c

    View Slide

  5. jgs
    00000011
    Case Study

    View Slide

  6. jgs
    00000011
    Homework
    § You won’t submit yet
    § Draft the source code. It will be discussed in our next lecture
    Problem to solve:
    1. A data structure to store flow charts
    2. Nodes?
    3. Types?
    4. Data / Content?
    5. How to connect?
    6. Who does the checking? When?

    View Slide

  7. jgs
    Case Study
    A translator

    View Slide

  8. jgs
    00000010
    [ - < < ( - ) > > ]
    [ ( < - > ) ]
    main () {
    home
    if(){
    if(){
    while() {
    whatever
    }
    }
    }
    }
    home () {
    while() {
    if() {
    something
    }
    }
    }
    Case Study

    View Slide

  9. jgs
    00000011
    The Blob
    public class Main {
    public static void main(String[] args) throws Exception {
    String text;
    // read text file
    File file = new File("/Users/Desktop/input.txt");
    BufferedReader br = new BufferedReader(new FileReader(file));
    String str;
    while ((str = br.readLine()) != null) {
    text = text + str;
    System.out.println(str);
    }
    // split words
    Vector tokens = new Vector();
    String line;
    int counterOfLines = 1;
    do {
    int eolAt = text.indexOf(/*System.lineSeparator()*/"\n");
    if (eolAt >= 0) {
    line = text.substring(0, eolAt);
    if (text.length() > 0) text = text.substring(eolAt + 1);
    } else {
    line = text;
    text = "";
    }
    splitLine(counterOfLines, line);
    counterOfLines++;
    } while (!text.equals(""));
    }
    // token classification
    int index = 0;
    char currentChar = ' ‘;
    String string = "";
    if (line.equals("")) return;
    // etc...

    View Slide

  10. jgs
    00000011
    Top-Down Stepwise Refinement (step 1)
    public class Main {
    public static void main(String[] args) throws Exception {
    String text = readTextFile (path);
    Vector tokens = splitWords (text);
    translate (tokens);
    }

    View Slide

  11. jgs
    00000011
    Top-Down Stepwise Refinement (step 2)
    public static String readTextFile (String path) {
    File file = new File (path);
    BufferedReader br = new BufferedReader(new FileReader(file));
    String str;
    while ((str = br.readLine()) != null) {
    text = text + str;
    }
    }
    public static String splitWords (String text) {
    // code here ...
    do {
    int eolAt = text.indexOf("\n");
    if (eolAt >= 0) {
    // code here ...
    } else {
    // code here ...
    }
    // a lot of code here !
    } while (!text.equals(""));
    }
    public static void translate (Vector tokens) {
    // more code ...
    }

    View Slide

  12. jgs
    00000011
    Top-Down Stepwise Refinement (step 3)
    public static void createToken (int row, String line) {
    if ( ... ) {
    } else if ( ... ) {
    } else if ( ... ) {
    // etc.
    }
    }

    View Slide

  13. jgs
    00000011
    What about translate?
    main () {
    home
    if(){
    if(){
    while() {
    whatever
    }
    }
    }
    } [ - < < ( - ) > > ]
    Input:
    Output:

    View Slide

  14. jgs
    00000011
    Top-Down Stepwise Refinement (step 4)
    private static int currentToken=0;
    public static void translate (Vector tokens) {
    while (curentToken < tokens.size()) {
    checkMethod();
    }
    }
    // checkMethod()
    // checkIf()
    // checkWhile()
    // checkInstruction()

    View Slide

  15. jgs
    Summary

    View Slide

  16. jgs
    00000011
    Summary
    § Split the problem in Tasks
    One method/function do one and only one specific Task
    § A Tasks enclose Steps (sequences, loops and conditions)
    Take advantage of recursion

    View Slide

  17. jgs
    00000011
    Homework
    Read:
    § On the Criteria To Be Used in Decomposing Systems into Modules
    D.L. Parnas
    Communications of the ACM
    April 1972

    View Slide

  18. jgs
    CSE 564 Software Design
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Fall 2021
    Copyright. These slides can only be used as study material for the class CSE564 at ASU.
    They cannot be distributed or used for another purpose.

    View Slide