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

CSE564 Lecture 04

CSE564 Lecture 04

Software Design
Modularization
(202101)

Javier Gonzalez-Sanchez
PRO

September 04, 2020
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSE 564 Software Design Lecture 04: Modularization Dr. Javier

    Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs Previously …

  3. jgs 00000010 [ - < < ( - ) >

    > ] [ ( < - > ) ] main () { home if(){ if(){ while() { whatever } } } } home () { while() { if() { something } } } Case Study
  4. jgs 564 00000100 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); }
  5. jgs 564 00000100 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 ... }
  6. jgs 564 00000100 Top-Down Stepwise Refinement (step 3) public static

    void createToken (int row, String line) { if ( ... ) { } else if ( ... ) { } else if ( ... ) { // etc. } }
  7. jgs 564 00000100 What about translate? Input:

  8. jgs 564 00000100 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() main () { home if(){ if(){ while() { whatever } } } } [ - < < ( - ) > > ] Output:
  9. jgs 564 00000100 Assignment 01 § Due Date: Thursday Sept

    2, 6:00 PM (AZ time). § Submit Individually (or team of 2). Only 1 student submit BUT be sure both names are included using the JavaDoc @author label § Source Code in Java (SHOULD compile and run) § Show your skills for readability (make your code easy to read) – Clean Code § Use Javadoc (correctly) § If you are not familiar with Java Guidelines, review https://google.github.io/styleguide/javaguide.html § Input is a txt file (path is to be received as parameter to main). § Output is to be printed on screen § Do not make assumptions. If you have a question, Ask
  10. jgs Modularization

  11. jgs 564 00000100 Timeline 1971 Wirth 1972 Parnas

  12. jgs 564 00000100 Decomposing Systems into Modules (1972) On the

    Criteria To Be Used in Decomposing Systems into Modules April 1972 D.L. Parnas Communications of the ACM Pioneer of software engineering ACM Fellow Developed the concept of information hiding
  13. jgs 564 00000100 • What criteria to use? • Niklaus

    Wirth. • Information Hiding : A data structure, its internal linking, accessing procedures and modifying procedures are part of a single module • What is a module? • What is the difference of Function vs Module? • What is the difference of Task vs Responsibility?
  14. jgs 564 00000100 Decomposing Systems into Modules (1972) • Modularization

    Design decisions / independent modules • It improves flexibility and comprehensibility • What criteria to use in dividing the system into modules? Rule A: Information Hiding – data, getters, and setters in one module Rule B: A set of related tasks must live in the same module
  15. jgs 564 00000100 Wirth + Parnas • Niklaus Wirth. •

    Each major step in the process a module. • Begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others. • In some cases, modules will not correspond to stages in the processing.
  16. jgs 564 00000100 Concepts • Module is a responsibility assignment

    rather than a subprogram. • Module specification = its inputs, its outputs its interfaces • Small enough and simple enough to be thoroughly understood • Independent development of modules • Comprehensibility: they make easy to understand parts, connections, and the whole.
  17. jgs 564 00000100 Summary § Functions are tasks. § One

    function perform one task. If needed (size, complexity) split in subtasks § A module encapsulate a responsibility § Responsibility include one or more tasks § A module encapsulate data shared by a group of tasks § How many modules and Which ones? § How many functions and in Which Module?
  18. jgs 564 00000100 Questions

  19. jgs CSE 564 Software Design Javier Gonzalez-Sanchez, Ph.D. javiergs@asu.edu 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.