DOC PREVIEW
UT Arlington CSE 3302 - Modules and separate compilation

This preview shows page 1-2-3-4-5-34-35-36-37-68-69-70-71-72 out of 72 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 3302Lecture'10:'Modules'and'separate'compila5on23'Feb'2010Nate'NystromUniversity'of'Texas'at'ArlingtonThursday, February 25, 2010ModulesKey'to'buildi ng'large'soDware'systems'is'ability'to'organize'the'program'into'modules'with'clean,'small'interfacesA'module'iden5fies'an'abstrac5on'in'the'program◾e.g.,%a%logical%component,%an%abstract%data%type2Thursday, February 25, 2010Advantages of modularityaggrega5onencapsula5onindependenceseparate'compila5oncode'reuse3Thursday, February 25, 2010AggregationModules'provide'a'higherJlevel'organiza5on'of'the'programEasier'to'keep'track'of'what'different'parts'of'the'program'are'supposed'to'do4Thursday, February 25, 2010EncapsulationInforma5on'hidingImplementa5on'details'can'be'made'not'visible'to'other'modulesCan'reimplement'module'without'affec5ng'others'5Thursday, February 25, 2010Independenceminimize'dependencies'between'modulesmodule'interface'should'specify'dependenciesmakes'it'possible'to'develop'on e'part'of'th e'program'independently'of'other'parts6Thursday, February 25, 2010Separate compilationCan'compile'a'mod ule'separately'from'othersIf'one'module'changes,'only'that'module'needs'to'be'recompiledEach'module'can'be'compiled'independently,'checking'against'the'interfaces'of'the'other'modules.During'linking,'resolve'references'from'one'module'to'another,'construc5ng'a'complete'program.7Thursday, February 25, 2010Code reuseCan'reuse'modules'in'other'programs'if'they'provide'other'generalJpurpose'func5onalityExamples:◾libraries◾frameworks8Thursday, February 25, 2010ModulesSeparate'specifica-on/and/implementa-on◾specifica5on◾describes%what%a%piece%of%code%is%supposed%to%do◾provided%by%interfaces◾implementa5on◾describes%how%to%do%it◾provided%by%modules9Thursday, February 25, 2010InterfacesNo,'not'Java'interfaces!◾more'on'that'laterAn'interface'is:◾Collec5on'of'types◾Data'declara5ons◾Pro cedure'signatures10Thursday, February 25, 2010ModulesImplementa5ons'for'proceduresAddi5onal'data'and'procedures◾not'present'in'the'interface◾private'and'not'available'to'other'moduelesIni5aliza5on'code11Thursday, February 25, 2010Language supportMany'languages'provide'modules'or'moduleJlike'structuresBut'they'use'different'names:◾Pascal'–'units◾Ada'–'packages◾Java'–"packages,"classes◾ML'–'structs'(but'usually'just'called'modules)◾ModulaJ3'–'modules12Thursday, February 25, 2010Modula-3We’ll'explore'the'essence'of'modu les'usi ng'Mod ul aJ3Why'M3?◾Not'clu^ered'with'other'features'(viz.'objects)◾Not'completely'ad'hoc'(C)13Thursday, February 25, 2010Separating spec and implementationTwo'constructs:◾Interfaces◾Modules14Thursday, February 25, 2010Modula-3 interfacesInterface'for'a'Util'module'that'provides'u5lity'func5ons'for'arrays'of'integersINTERFACE-Util;TYPE-A-=-ARRAY-OF-INTEGER;PROCEDURE-Sort(a:-A);PROCEDURE-Max(a:-A):-INTEGER;END-Util.15Provides'signatures'for'two'procedures'opera5ng'on'type'A.Defines'a'type'AThursday, February 25, 2010Modula-3 modulesImplementa5on'of'the'Util'module:MODULE-Util-EXPORTS-Util;PROCEDURE-Sort(a:-A)-=---BEGIN-(*-code-for-Sort-*)-END-Sort;PROCEDURE-Max(a:-A):-INTEGER-=---BEGIN-(*-code-for-Max-*)-END-Max;PROCEDURE-Compare(a:-A,-b:-A):-INTEGER-=---BEGIN-(*-code-for-Compare-*)-END-Compare;END-Util.16EXPORTS'indicates'what'interface'this'module'implements.'Thursday, February 25, 2010Modula-3 modulesImplementa5on'of'the'Util'module:MODULE-Util-EXPORTS-Util;PROCEDURE-Sort(a:-A)-=---BEGIN-(*-code-for-Sort-*)-END-Sort;PROCEDURE-Max(a:-A):-INTEGER-=---BEGIN-(*-code-for-Max-*)-END-Max;PROCEDURE-Compare(a:-A,-b:-A):-INTEGER-=---BEGIN-(*-code-for-Compare-*)-END-Compare;END-Util.17Module'can'define'more'members'than'tho se'in'i nterface.''Not'visible'to'other'modules.Thursday, February 25, 2010FeaturesModules'and'interfaces◾specify'a'namespace'collec5ng'related'types,'declara5ons,'and'proceduresInterface◾specifies'names'that'are'exported'(i.e.,'visibl e'to)'other'modulesModule◾defines'the'implementa5on'of'a'given'interface◾implementa5on'may'include'members'not'exported18Thursday, February 25, 2010CC'supports'ad/hoc/modulesLarge'programs'are'modularized'by'breaking'the'program'into'mul5ple'.c'filesEach'.c'file'is'compiled'into'a'object'(.o)'fileMul5ple'.o'files'are'linked'together'into'an'executable'or'libraryUse'header'(.h)'files'to'share'declara5ons19Thursday, February 25, 2010Separate compilation in CCan'compile'each'.c'fi le'separatelyCan'refer'to'code'in'other'.c'files'using'extern◾extern-int-strcmp(const-char-*,-const-char-*);◾extern-float-BIG_ARRAY[N];20Thursday, February 25, 2010Separating spec and implementationBy/conven-on,'separate'specifica5on'and'implementa5on'by'using'header'(.h)'filesPut'specifica5on'for'a'module'in'.h'file◾type'declara5ons'(typedefs,'structs)◾variable'declara5ons◾func5on'declara5ons'(prototypes)Put'implementa5on'in'.c'fileBut'not'quite:◾some'implementa5on'in'.h'file◾inline'func5ons,'macros,'C++'templates21Thursday, February 25, 2010Information hidingBy'default,'any'declara5on'in'file'1'can'be'made'visible'in'file'2'by'declaring'a'prototype'in'file'2One'mechanism'for'informa5on'hi di ng'in 'C:'static◾static'variables'and'func5ons'in'one'file'are'not'visible'in'other'files22Thursday, February 25, 2010Modules in JavaSeparate'specifica5on'and'implementa5on'with:◾Specifica5on'given'by'interfaces◾Implementa5on'given'in'classesBut,'separa5on'not'enforced◾not'required'to'use'interfaces◾can'use'other'classes'directly23Thursday, February 25, 2010Java interfacesinterface-IntRef-{----void-set(int-x);----int-get();}Specifies'a'set'of'public'methods'all'classes'implemen5ng'the'interface'must'provide.class-C-implements-IntRef-{----private-int-v;----public-void-set(int-x)-{-v-=-x;-}-----public-int-get()-{-return-v;-}}24Thursday, February 25, 2010PackagesA'package'is'a'collec5on'of'related'classes'and'interfaces.Namespaces'provided'by'packages◾but,'packages'don’t'separate'specifica5on'and'implementa5on◾no'way'to'say'several 'mutual ly /dependent'classes'implement'several'mutually'dependent'interfaces'◾can'declare'classes,'interface,'methods,'fields'to'be'packageJscoped'––'visibl e'onl y'to'other'members'of'the'package.25Thursday, February 25, 2010Using a module26Thursday, February 25, 2010Modula-3


View Full Document

UT Arlington CSE 3302 - Modules and separate compilation

Documents in this Course
Smalltalk

Smalltalk

11 pages

Syntax

Syntax

5 pages

Syntax

Syntax

5 pages

JAVA

JAVA

57 pages

Semantics

Semantics

41 pages

Control

Control

74 pages

Load more
Download Modules and separate compilation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Modules and separate compilation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Modules and separate compilation 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?