Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3: Modularization

Similar presentations


Presentation on theme: "Chapter 3: Modularization"— Presentation transcript:

1 Chapter 3: Modularization

2 Objectives Understanding Documentation Learn about documentation
Learn about the advantages of modularization Learn how to modularize a program Declare local and global variables and constants Create hierarchy charts

3 Documentation Documentation
All supporting material that goes with a program Two major categories: for users and for programmers User Documentation: End users (people who use computer programs) Program Documentation Internal program documentation: comments within code External program documentation: supporting paperwork written before programming begins

4 Output Documentation Figure 3-2 Inventory records displayed in a GUI environment Figure Inventory records displayed in a running program

5 Figure 3-6 Inventory file description
Input Documentation Describes what input is available to produce the output File description: Describes data stored in a file Indicates fields, data types, and lengths Figure 3-6 Inventory file description

6 Completing Documentation
Program documentation may contain: Output design Input description Flowcharts Pseudocode Program code listing User documentation may contain: Manuals Instructional material Operating instructions

7 Modularization Modularization: breaking a large program into modules
Advantages of modularization: Provides abstraction Allows multiple programmers to work simultaneously Allows code reuse Makes identifying structures easier

8 Modularization Module: Invoke (call) a method is to execute it
Unit of code that performs one small task Called a subroutine, procedure, function, or method Invoke (call) a method is to execute it Calling method invokes the called method Program contains unlimited number of methods Each method can be called unlimited number of times

9 Modularization Provides Abstraction
Focuses on important properties while ignoring non- essential details Avoids low-level details Makes complex tasks look simple High-level programming languages allow English-like vocabulary One statement corresponds to dozens of machine instructions Modules provide another way to achieve abstraction

10 Modularization Provides Abstraction (continued)
To-do list without abstraction Pick up laundry basket Put laundry basket in car Drive to laundromat Get out of car with basket Walk into laundromat Set basket down . . . To-do list with abstraction Do laundry Call Aunt Nan Start term paper

11 Modularization Allows Multiple Programmers to Work on a Problem
Commercial programs rarely written by a single programmer Development time is significantly reduced Large programming projects can be divided into modules Modules can be written by different programmers or programming teams

12 Modularization Allows You to Reuse Your Work
Subroutines that are useful should be used more than once in a program Example: routine that checks the current date Instructions placed in their own module are easy to port to other applications Reusability: the ability to use modules in a variety of applications Reliability: assurance that a module has been tested and proven to function correctly Reliable software saves times and money

13 Modularizing a Program
Most programs contain a main program Contains the mainline logic Accesses other modules or subroutines Rules for naming modules different for every programming language For this text: Must be one word Should be meaningful Followed by a set of parentheses Corresponds to module naming in Java, C++, C#

14 Modularizing a Program (continued)
Table 3-1 Suggested identifiers for a module that calculates an employee’s gross pay

15 Modularizing a Program (continued)
Calling program (or calling module): one that uses another module Flowchart symbol for calling a module: rectangle with bar across the top Flowchart for the module Start symbol: contains module name Stop symbol: contains exit or return When a module is called, logic transfers to the model When module ends, logic transfers back to the caller

16 Figure 3-9 Logic from Figure 3-8 using a method
Figure 3-8 Sample logic Figure 3-9 Logic from Figure 3-8 using a method

17 Figure 3-10 Logic from Figure 3-9 using two methods

18 Modularizing a Program (continued)
Method is encapsulated in another method if it is contained in another method Knowing when to break a module into its own subroutines or submodules is an art Best practice: place together statements that contribute to one specific task Functional cohesion: extent to which the statements contribute to the same task


Download ppt "Chapter 3: Modularization"

Similar presentations


Ads by Google