What is a Module
description
Transcript of What is a Module
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 1/11
MODULARITY By: Andre Mayne
All rights reserved ©
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 2/11
What Is a Module?
• In software, a module is a part of
a program. Programs arecomposed of one or moreindependently developed modulesthat are not combined until the
program is linked. single modulecan contain one orseveral routines.
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 3/11
!ystems programming language
• "riginally used to write #ni$• %ata types and control structures close to most
machines
• now also a popular application programming language
&otable features
• all functions are call'by'value
•
Pointer (address) arithmetic• simple scope structure
• I*" and memory mgmt facilities provided by libraries
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 4/11
Why is this better?
• Easier to understand
• +asier to test and debug
• +asier to reuse code• +asier to make changes
Int main () char -stringsM/0!12I&3!45Int nstrings52ead!trings(strings, 6nstrings,M/0!12I&3!, stdin)5
!ort!trings(strings,nstrings)5Write!trings(strings,0nstrings, stdout)5return0758
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 5/11
Why is this etter!
• +asier to understand
• Easier to test and deug
•
+asier to reuse code• +asier to make changes
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 6/11
Why is this better?
• +asier to understand
•
+asier to test and debug• Easier to reuse "ode
• +asier to make changes
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 7/11
Why is this better?
• +asier to understand
• +asier to test and debug
•
+asier to reuse code• Easier to #a$e "hanges
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 8/11
!eparate 9ompilation
Move string array into separate :le
• %eclare interface instringarray.h
• Provide implementation instringarray.c
•
llows re'use by other programs
stringarray.h+$tern0void02ead!trings(char --strings,int-nstrings,
Int ma$strings, ;I<+ -fp)5
+$tern void Write!trings(char --strings,int nstrings, ;I<+ -fp)5
+$tern void !ort!trings(char --strings,int nstrings)5
+$ternint 9ompare!trings(char -string=, char -string>)5
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 9/11
bstract0%ata01ypes
Module supporting operations on single data structure
Interface declares operations, not data structure
Implementation is hidden from client (encapsulation)
#se features of programming language to ensure encapsulation
9ommon0practice
llocation and deallocation of data structure handled bymodule
&ames of functions and variables begin with @modulenameA Provide as much generality*Be$ibility in interface as possible
#se void pointers to allow polymorphism
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 10/11
7/21/2019 What is a Module
http://slidepdf.com/reader/full/what-is-a-module 11/11
)u##ary
• Modularity is $ey to good so(t*are
%ecompose program into modules
Provide clear and Be$ible interfaces
• Astra"t Data Ty&es
Modules supporting operations on data structure
Well'designed interfaces hide implementations, but provide Be$ibility
Advantages
!eparate compilation
+asier to understand
+asier to test and debug
+asier to reuse code
+asier to make changes