+ All Categories
Home > Documents > Information Hiding - University of Waterloo · Information Hiding -1 The concept of information...

Information Hiding - University of Waterloo · Information Hiding -1 The concept of information...

Date post: 14-Oct-2019
Category:
Upload: others
View: 11 times
Download: 0 times
Share this document with a friend
102
Information Hiding Daniel M. Berry
Transcript
Page 1: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Information Hiding

Daniel M. Berry

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 1

Page 2: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Information Hiding -1

The concept of information hiding (IH) comesfrom the seminal paper,

“On the criteria to be used in decomposingsystems into modules”, CACM, Dec., 1972

by David L. Parnas.

The purpose of information hiding is to obtaina modularization of the code of a system thatisolates changes into single modules.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 2

Page 3: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Information Hiding -2

Information hiding is a way to use abstractdata types and abstract objects, such asprovided byg Ada packagesg Simula classesg C++ classes

I assume that you know at least one of these!

If you don’t, then go learn!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 3

Page 4: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O -1

It is necessary to teach exploitation ofabstract data types and objects (ADT&O).

I have found many people writing FORTRANcode in Ada syntax or C code in C++ syntax.

On the other hand, it is possible to exploitADT&O even in assembly language andFORTRAN!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 4

Page 5: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O -2

What’s a nice programming topic like youdoing in a real rough requirementsengineering course like this?

g ADT&O is a good way to organize a domainmodel

g ADT&O is a good way to organize asoftware design

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 5

Page 6: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O -3

Remember that you may have to do somedesign to discover all requirements.

With ADT&O, the domain model and designcan be built without exposing implementationdetails!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 6

Page 7: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O -4

In my experience, if I program with ADT&Ousing information hiding, my modules end upbeing the types and objects of the domainmodel.

So even if I am thinking implementation, I endup with a domain model!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 7

Page 8: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O and IH -1

For those of you who are implementation-bound in your thinking, ADT&O withinformation hiding frees you from thinkingimplementation.

ADT&O with IH gives you a way of thinking atan abstract level without having to worryabout whether you can implement, becauseyou can!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 8

Page 9: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

ADT&O and IH -2

You will see an entirely different way ofthinking about problems, in which you workwith problem-level concepts rather than moretraditional data- or control-flow concepts.

If you’re already thinking this way, bravo!

If not, then learn!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 9

Page 10: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Sample Problem

Requirements:

The KWIC index system accepts an orderedset [sic] of lines, each line is an ordered set[sic] of words, and each word is an orderedset [sic] of characters.

Any line may be “circularly shifted” byrepeatedly removing the first word andappending it at the end of the line. The KWICindex system outputs a listing of all thecircular shifts of all lines in alphabetical order.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 10

Page 11: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

List of Six Lines

Make - A Program for Maintaining Computer ProgramsReference Manual for the Ada Programming LanguageThe NYU Ada/Ed System, An OverviewProgram Design LanguageSoftware Development Processor User Reference ManualThe Ina Jo Reference Manual

The next slide shows the KWIC (KeyWord InContext) index of the above lines.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 11

Page 12: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Make - A Program for Maintaining Computer Programs [Fel78]Make - A Program for Maintaining Computer Programs [Fel78]

Reference Manual for the Ada Programming Language [ADA81]The NYU Ada/Ed System, An Overview [NYU81]

The NYU Ada/Ed System, An Overview [NYU81]Make - A Program for Maintaining Computer Programs [Fel78]

Program Design Language [CFG75]Software Development Processor User Reference Manual [Yav80]

Make - A Program for Maintaining Computer Programs [Fel78]Reference Manual for the Ada Programming Language [ADA81]

The Ina Jo Reference Manual [LSSE80]The Ina Jo Reference Manual [LSSE80]

Program Design Language [CFG75]Reference Manual for the Ada Programming Language [ADA81]

Make - A Program for Maintaining Computer Programs [Fel78]Make - A Program for Maintaining Computer Programs [Fel78]

Reference Manual for the Ada Programming Language [ADA81]Software Development Processor User Reference Manual [Yav80]

The Ina Jo Reference Manual [LSSE80]The NYU Ada/Ed System, An Overview [NYU81]

The NYU Ada/Ed System, An Overview [NYU81]Software Development Processor User Reference Manual [Yav80]

Program Design Language [CFG75]Make - A Program for Maintaining Computer Programs [Fel78]

Reference Manual for the Ada Programming Language [ADA81]Make - A Program for Maintaining Computer Programs [Fel78]

Reference Manual for the Ada Programming Language [ADA81]Software Development Processor User Reference Manual [Yav80]

The Ina Jo Reference Manual [LSSE80]Software Development Processor User Reference Manual [Yav80]

The NYU Ada/Ed System, An Overview [NYU81]Reference Manual for the Ada Programming Language [ADA81]

The Ina Jo Reference Manual [LSSE80]The NYU Ada/Ed System, An Overview [NYU81]

Software Development Processor User Reference Manual [Yav80]

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 12

Page 13: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

KWIC Index of Above Lines

First 5 lines of Index:

Make - A Program for Maintaining Computer Programs [Fel78]Make - A Program for Maintaining Computer Programs [Fel78]

Reference Manual for the Ada Programming language [Ada81]The NYU Ada/ed System, An Overview [NYU81]

The NYU Ada/ed System, An Overview [NYU81]ccccccc

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 13

Page 14: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Two Modularizations

Parnas shows first a conventionalmodularization and then one that does a betterjob of being modifiable.

Modularization 1: Brand X

Modularization 2: Brand DLP

Guess which one is supposed to be better!

The textual module descriptions are fromParnas himself.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 14

Page 15: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -1

outputalphabetizercircular_

shifterinput

KWICModularization 1

BRAND X:

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 15

Page 16: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -2

alphed_cs_line_indexcs_line_indexline_index

wordsDATA STRUCTURE DIAGRAM

541897

1032

51

222111

4321

567

1 1

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 16

Page 17: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -3

Module 1: Input. This module reads the datalines from the input medium and stores themin core for processing by the remainingmodules. The characters are packed four to aword, and an otherwise unused character isused to indicate the end of a word. An indexis kept to show the start of each line.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 17

Page 18: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -4

Module 2: Circular Shift. This module iscalled after the input module has completedits work. It prepares an index which gives theaddress of the first character of each circularshift, and the original index of the line in thearray made up by module 1. It leaves itsoutput in core with words in pairs (original linenumber, starting address).

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 18

Page 19: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -5

Module 3: Alphabetizing. This module takesas input the arrays produced by modules 1and 2. It produces an array in the same formatas that produced by module 2. In this case,however, the circular shifts are listed inanother order (alphabetically).

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 19

Page 20: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -6

Module 4: Output. Using the arraysproduced by module 3 and module 1, thismodule produces a nicely formatted outputlisting of all of the circular shifts. In asophisticated system the actual start of eachline will be marked, pointers to furtherinformation may be inserted, and the start ofthe circular shift may actually not be the firstword in the line, etc.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 20

Page 21: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -7

Module 5: Master Control. This moduledoes little more than control the sequencingamong the other four modules. It may alsohandle error messages, space allocation, etc.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 21

Page 22: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -8

Parnas says:

It should be clear that the above does notconstitute a definitive document. Much moreinformation would have to be supplied beforework could start. The defining documentswould include a number of pictures [as above]showing core formats, pointer conventions,calling conventions, etc. All of the interfacesbetween the four modules must be specifiedbefore work could begin.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 22

Page 23: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -9

I add the additional defining documents usingAda notation:

procedure KWIC istype PAIR is record

line_no:INTEGER;character_no:INTEGER;

end record;type INDEX_TABLE is array

(INTEGER range <>) of PAIR;large_no: constant INTEGER:=MAX_INT;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 23

Page 24: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -10

words:STRING(1..large_no);line_index:INDEX_TABLE(1..large_no);cs_line_index:INDEX_TABLE(1..large_no);alphed_cs_line_index:INDEX_TABLE(1..large_no);

procedure input is separate;procedure make_circular_shifts is separate;procedure alphabetize is separate;procedure output is separate;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 24

Page 25: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -11

begininput;make_circular_shifts;alphabetize;output;

end KWIC;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 25

Page 26: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -12

separate(KWIC)procedure input isbegin

null;end;

separate(KWIC)procedure make_circular_shifts isbegin

null;end;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 26

Page 27: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -13

separate(KWIC)procedure alphabetize isbegin

null;end;

separate(KWIC)procedure output isbegin

null;end;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 27

Page 28: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 1 -14

More from Parnas:

This is a modularization in the sense meant byall proponents of modular programming [circa1972]. The system is divided into a number ofmodules with well-defined interfaces; eachone is small enough and simple enough to bethoroughly understood and well programmed.Experiments on a small scale indicate that thisis approximately the decomposition whichwould be proposed by most programmers forthe task specified.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 28

Page 29: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -1

Alphabetized_Circular_Shifts

Line_Storage

Modularization 2

BRAND DLP:

dellinedelwordlineswordscharscharsetchar

Circular_Shifts

ithalph

output

input

KWIC

cslinescswordscscharscscharcssetup

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 29

Page 30: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -2

Module 1: Line Storage. This moduleconsists of a number of functions orsubroutines which provide the means bywhich the user of the module may call on it.The function call CHAR(r,w,c) will have asvalue an integer representing the c thcharacter in the r th line, w th word. A callsuch as SETCHAR(r,w,c,d) will cause the c thcharacter in the w th word of the r th line to bethe character represented by d (i.e.,CHAR(r,w,c) = d).

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 30

Page 31: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -3

WORDS(r) returns as value the number ofwords in line r. There are certain restrictionsin the way that these routines may be called; ifthese restrictions are violated the routines“trap” to an error-handling subroutine whichis to be provided by the users of the routine.Additional routines are available which revealto the caller the number of words in any line,the number of lines currently stored, and thenumber of characters in any word....

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 31

Page 32: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -4

Module 2: Input. This module reads theoriginal lines from the input media and callsthe line storage module to have them storedinternally.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 32

Page 33: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -5

Module 3: Circular Shifter. The principalfunctions provided by this module are analogsof functions provided in module 1. Themodule creates the impression that we havecreated a line holder containing not all of thelines but all of the circular shifts of the lines.Thus the function call CSCHAR(l,w,c) providesthe value representing the c th character in thew th word of the l th circular shift.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 33

Page 34: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -6

It is specified that (1) if i < j then the shifts ofline i precede the shifts of line j, and (2) foreach line the first shift is the original line, thesecond shift is obtained by making a one-wordrotation to the first shift, etc. A functionCSSETUP is provided which must be calledbefore the other functions have their specifiedvalue....

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 34

Page 35: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -7

Module 4: Alphabetizer. This moduleconsists principally of two functions. One,ALPH, must be called before the other willhave a defined value. The second, ITH, willserve as an index. ITH(i) will give the index ofthe circular shift that comes i th in thealphabetical ordering.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 35

Page 36: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -8

Module 5: Output. This module will give thedesired printing of set [sic] of lines or [sic]circular shifts.

Module 6: Master Control. Similar infunction to the modularization above.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 36

Page 37: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -9

References 3 and 8 of Parnas’s paper giveformal definitions of Modules 1, 3, and 4 (theinteresting ones!!).

We give Ada module structure to which thesedefinitions can be attached.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 37

Page 38: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -10

package LINE_STORAGE isfunction char (l,w,c:INTEGER)

return CHARACTER;procedure setchar (l,w,c:INTEGER;

d:CHARACTER);function chars (l,w:INTEGER)

return INTEGER;function words (l:INTEGER)

return INTEGER;function lines return INTEGER;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 38

Page 39: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -11

...-- error handling exceptions

end LINE_STORAGE;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 39

Page 40: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -12

with LINE_STORAGE;use LINE_STORAGE;package CIRCULAR_SHIFTS is

procedure cssetup;function cschar (l,w,c:INTEGER)

return CHARACTER;function cschars (l,w:INTEGER)

return INTEGER;function cswords (l:INTEGER)

return INTEGER;function cslines return INTEGER;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 40

Page 41: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -13

-- error handling exceptionsend CIRCULAR_SHIFTS;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 41

Page 42: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -14

with CIRCULAR_SHIFTS;use CIRCULAR_SHIFTS;package ALPHABETIZED_CIRCULAR_SHIFTS is

procedure alph;function ith(i:INTEGER)

return INTEGER;-- error handling exceptions

end ALPHABETIZED_CIRCULAR_SHIFTS;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 42

Page 43: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -15

with ALPHABETIZED_CIRCULAR_SHIFTS;use ALPHABETIZED_CIRCULAR_SHIFTS;procedure KWIC is

procedure input is separate;procedure output is separate;

begininput;alph;output;

end KWIC;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 43

Page 44: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -16

with LINE_STORAGE; use LINE_STORAGE;separate(KWIC);procedure input is

l,w,c:INTEGER;d:CHARACTER;

begin-- read in characters one by one into d, breaking into-- words and lines, setting the line, word, and-- character indices, l, w, and c, and doing for each,setchar(l,w,c,d);

end input;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 44

Page 45: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -17

with ALPHABETIZED_CIRCULAR_SHIFTS,CIRCULAR_SHIFTS,TEXT_IO;

use ALPHABETIZED_CIRCULAR_SHIFTS,CIRCULAR_SHIFTS,TEXT_IO;

separate(KWIC);procedure output is

l:INTEGER;begin

for i in 1..cslines() loopl:=ith(i);

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 45

Page 46: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Modularization 2 -18

for w in 1..cswords(l) loopfor c in 1..cschars(l,w) loop

-- in the proper-- place for the-- fancy output doput(cschar(l,w,c));

end loop;end loop;

end loop;end output;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 46

Page 47: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -1

Parnas says about the two modularizations:

General. Both schemes will work. The first isquite conventional, and the second has beenused successfully in a class project [ eachstudent programmed a different module andcomplete programs were built in all possiblecombinations]. Both will reduce theprogramming to the relatively independentprogramming of a number of small,manageable, programs.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 47

Page 48: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -2

Note first that the two decompositions mayshare all data representations and accessmethods. Our discussion is about twodifferent ways of cutting up what may be thesame object. A system built according todecomposition 1 could conceivably beidentical after assembly to one built accordingto decomposition 2.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 48

Page 49: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -3

We now use Ada facilities to cause the code ofthe two modularizations to be (almost)identical

I now provide package bodies for thepackages of the Ada rendition ofModularization 2 using code from the Adarendition of Modularization 1!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 49

Page 50: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -4

package body LINE_STORAGE istype PAIR is record

line_no:INTEGER;character_no:INTEGER;

end record;type INDEX_TABLE is array

(INTEGER range <>) of PAIR;large_no: constant INTEGER:=MAX_INT;

the_words:STRING(1..large_no);line_index:INDEX_TABLE(1..large_no);

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 50

Page 51: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -5

function char (l,w,c:INTEGER)return CHARACTER is ...

procedure setchar (l,w,c:INTEGER;d:CHARACTER) is ...

function chars (l,w:INTEGER)return INTEGER is ...

function words (l:INTEGER)return INTEGER is ...

function lines return INTEGER is ......

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 51

Page 52: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -6

☛ pragma IN_LINE(char,setchar);-- error handling exceptions

end LINE_STORAGE;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 52

Page 53: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -7

package body CIRCULAR_SHIFTS istype PAIR is record

line_no:INTEGER;character_no:INTEGER;

end record;type INDEX_TABLE is array

(INTEGER range <>) of PAIR;large_no: constant INTEGER:=MAX_INT;

cs_line_index:INDEX_TABLE(1..large_no);

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 53

Page 54: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -8

procedure cssetup is ...function cschar (l,w,c:INTEGER)

return CHARACTER is ...function cschars (l,w:INTEGER)

return INTEGER is ...function cswords (l:INTEGER)

return INTEGER is ...function cslines return INTEGER is ...

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 54

Page 55: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -9

☛ pragma IN_LINE(cssetup,cschar);-- error handling exceptions

end CIRCULAR_SHIFTS;

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 55

Page 56: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -10

package body ALPHABETIZED_CIRCULAR_SHIFTS istype PAIR is record

line_no:INTEGER;character_no:INTEGER;

end record;type INDEX_TABLE is array

(INTEGER range <>) of PAIR;large_no: constant INTEGER:=MAX_INT;

alphed_cs_line_index:INDEX_TABLE(1..large_no);

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 56

Page 57: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -11

procedure alph is ...function ith(i:INTEGER)

return INTEGER is ...☛ pragma IN_LINE(ith);

-- error handling exceptions

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 57

Page 58: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -12

The procedures that were left out-of-line arethose that were deemed likely to be out-of-linein Modularization 1.

In the resulting object code, all the datastructures end up in the same block, just as inModularization 1.

However, each data structure is visible only tothe procedures of the module from which itcame!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 58

Page 59: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -13

Parnas says:

The differences between the two alternativesare in the way they are divided into workassignments, and the interfaces betweenmodules. The algorithms used in both casesmight be identical. The systems aresubstantially different even if identical in therunnable representation.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 59

Page 60: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -14

This is possible because the runnablerepresentation need only be used for running;other representations are used for changing,documenting, understanding, etc. The twosystems will not be identical in those otherrepresentations.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 60

Page 61: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -15

changeability. There are a number of design[i.e., implementation] decisions which arequestionable and likely to change under manycircumstances. This is a partial list

1. Input format.2. The decision to have all lines stored in

core. For large jobs it may proveinconvenient or impractical to keep all ofthe lines in core at any one time.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 61

Page 62: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -16

3. The decision to pack the characters four toa word. In cases where we are workingwith small amounts of data it may proveundesirable to pack the characters; timewill be saved by a character per wordlayout. In other cases, we may pack, but indifferent formats.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 62

Page 63: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -17

4. The decision to make an index for thecircular shifts rather that [sic] store themas such. Again, for a small index or a largecore, writing them out may be thepreferable approach. Alternatively, we maychoose to prepare nothing duringCSSETUP. All computations could be doneduring the calls on the other functionssuch as CSCHAR.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 63

Page 64: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -18

I add to this:

CSSETUP is provided specifically to allowmany implementations.

g if the implementation needs some setup, then CSSETUP is non-empty

g If the implementation needs no set up,then CSSETUP is empty; if in addition,CSSETUP is inline, then it costsnothing!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 64

Page 65: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -19

Getting back to Parnas’s comments:

5. The decision to alphabetize the list once,rather than either (a) search for each itemwhen needed, or (b) partially alphabetize asis done in Hoare’s FIND.... In a number ofcircumstances it would be advantageous todistribute the computation involved inalphabetization over the time required toproduce the index.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 65

Page 66: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -20

Let us now examine each change and seewhich modules in each modularization need tobe modified to effect the change.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 66

Page 67: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -21Change Modularization

1 2iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiInput Input InputiiiiiiiiiiiiiiiiiiiiiiiiiiiiiLines all Linesin coreiiiiiiiiiiiiiiiiiiiiiiiiiiiii

Packing all LinesiiiiiiiiiiiiiiiiiiiiiiiiiiiiiStore CSs CS Alph CS

OutputiiiiiiiiiiiiiiiiiiiiiiiiiiiiiAlph on Alph Alphthe fly Output

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 67

Page 68: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Comparison -22

In Modularization 1, most changes affected allmodules!

In Modularization 2, each change affected onlyone module!

Fantastic!!!!!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 68

Page 69: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Kinds of Changes -1

Note though, that we have been talking aboutimplementation changes only.

Functionality changes are an entirely differentkind of animal.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 69

Page 70: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Kinds of Changes -2

For functionality changes, we must expect tohave new modules and new procedures addedto existing modules.

However, my experience is that a goodmodularization, that hides implementationchanges, shields very well against manyfunctionality changes.

Such changes go much easier with a gooddecomposition than without.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 70

Page 71: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

How to Decompose Well -1

We consider several methods to decomposesystems into modules whose internals areeasily modified independently.

All of these methods yield nearly the samedecomposition.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 71

Page 72: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

How to Decompose Well -2

The methods are

g Parnas’s methodg Nouns as module namesg Myers’s criteriag Britton & Parnas’s ideasg Booch’s ideasg other ideas

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 72

Page 73: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Parnas’s Method

Come up with a first cut decomposition.

Get a list of as many changes as you can thinkof; ... blue sky!

If the effect of each change is isolated to onemodule, you have a good decomposition.

If not, go back to the drawing board.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 73

Page 74: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Nouns as Module Names

In my experience, the general nouns of theproblem statement make good ADTs andthese ADTs make good modules.

In fact, Abbott, Booch, and Berzins & Luqisuggest starting with an informal strategy andits identified nouns.

This method was suggested in the earlierlecture titled “Survey of Methods andNotations” as a way to get a domain model!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 74

Page 75: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -1

Myers talks about cohesion and coupling.

Cohesion is the degree to which a module isdoing one and only one thing.

Coupling is the degree to which two modulescommunicate.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 75

Page 76: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -2

We want

high cohesion

and

low coupling.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 76

Page 77: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -3

Cohesion:

The procedures

print page footergoto next pageprint page header

are each more cohesive than the procedure

print page footer and the next page header

which does the work of all three in that order.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 77

Page 78: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -4

A single procedure or function is morecohesive as a module than an abstract datatype.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 78

Page 79: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -5

Coupling:

g no communication at all is less couplingthan parameter passing

g parameter passing is less coupling thancommon usage of global variables

g communicating with individual items isless coupling than communicating withdata structures

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 79

Page 80: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -6

So why are ADTs good modules despite thefact that an ADT is less cohesive than itsindividual operations?

An ADT groups together into one module allroutines that must share access to acollection of data structures, so that nothingoutside of the module needs to see these datastructures.

And ...

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 80

Page 81: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -7

An ADT causes outsiders to see these datastructures as single indivisible items ratherthan as their implementing data structures.

An ADT forces outsiders to pass these dataitems as parameters to the operations insteadof being able to directly access thecomponents of these items as shared globaldata structures.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 81

Page 82: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -8

That is, we suffer a slight reduction incohesiveness to obtain big reduction incoupling.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 82

Page 83: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Low

Low

Very High

Very High CouplingHidden Inside Module

Coupling

Coupling

Coupling

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 83

Page 84: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -9

There is another way to explain this; put alldata structures and procedures that have tobe modified together, and no more, into thesame module.

Thus, the data structures that implement apushdown stack and the operation bodies thatoperate on these structures should be in thesame module.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 84

Page 85: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -10

However, ...

For sure, do not put into this module thefunctions that implement a stack-oriented,postfix-polish operator pocket calculator.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 85

Page 86: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -11

Possibly, do not put into this moduleprocedures such as

procedure ptop(s:in out INTSTACKVAL;t: out INTEGER) is

begint:=top(s);pop(s);

end;

which can be defined using exportedoperations.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 86

Page 87: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -12

Why only possibly?

It may be useful to insist that ptop beimplemented by direct access to the datastructure.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 87

Page 88: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Myers’s Criteria -13

In fact, this is why we trade a slight reductionin cohesion for a big reduction in coupling.

Yes, the individual operations of the stackpackage are more cohesive than the package,but if you have to change one of thoseoperation bodies you probably have to changeall of them. So why not lump them alltogether?

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 88

Page 89: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Britton & Parnas’s Ideas -1

Britton and Parnas say:

The overall goal of the decomposition intomodules is the reduction of software cost byallowing modules to be designed,[implemented], and revised independently....

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 89

Page 90: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Britton & Parnas’s Ideas -2

Each module’s structure should be simpleenough that it can be understood fully; itshould be possible to change theimplementation of [ a module] withoutknowledge of the implementation of othermodules and without affecting the behavior ofother modules; [ and] the ease of making achange in the design should bear a reasonablerelationship to the likelihood of the changebeing needed.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 90

Page 91: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Booch’s Ideas -1

Booch adds to this discussion:

There is a pragmatic edge to these guidelines.In practice, the cost of recompiling the body ofa module is relatively small; only that unitneed be recompiled and application relinked.However the cost of recompiling the interfaceof a module is relatively high.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 91

Page 92: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Booch’s Ideas -2

Especially with strongly typed languages, onemust recompile the module interface, its body,all other modules that depend upon thisinterface, the modules that depend on thesemodules, and so on.

[emphasis is mine]

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 92

Page 93: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Booch’s Ideas -3

Thus, it is important to get the abstractiondefined right.

The closer the abstraction’s interface is to reallife, the less likely it is to change.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 93

Page 94: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Other Ideas -1

Still another criterion:

Build modules to make reuse convenient.

This causes ADTs to be designed to belogically complete. For example, if in oneapplication using a stack, you never need toclear the stack to empty or ask if the stack isempty, you put these operations in anyway.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 94

Page 95: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Other Ideas -2

Doing so

g increases chances of reuse in otherapplications of stacks

g reduces chances that interface will have tobe changed later; after all, the interface isexactly the abstraction; if the abstraction islogically complete, so is the interface.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 95

Page 96: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Other Ideas -3

How can you tell if the abstraction iscomplete?

One thing for sure, if you need an operation oto define another, then o is part of theabstraction. This accounts for the is_emptyfunction in a Stack module.

For the others, good ol’ experience is the onlyway to tell.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 96

Page 97: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -1

One point came up in discussion with one ofyou after hours:

We are admonished to avoid making designdecisions while writing requirementsdocuments.

We are admonished against doing designduring requirements analysis.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 97

Page 98: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -2

Parnas’s method for decomposing modules isclearly intended as a method for decomposingdesign.

However, it is a method for doing design whiledelaying implementation decisions.

Anything that is hidden can be changed andthus the issue for which it is a decision iseffectively delayed!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 98

Page 99: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -3

But given that this is a design technique, whydo I claim that Parnas’s decomposition is asuitable basis for building requirementdomain models?

In giving a domain model, we are trying toavoid pinning down the implementation, toavoid constraining the implementor beyondwhat is required to meet requirements.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 99

Page 100: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -4

However, the purpose of Parnas’s method isprecisely to allow any implementation.

We have proved for the KWIC example that themodularization allows implementations whosestructure bears no resemblence to that of themodules.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 100

Page 101: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -5

I claim that any Parnas decomposition doesnot constrain implementations beyond what isnecessary to meet requirements.

Moreover it turns out (and we can usuallyforce it to be!) that if the elements of thedecomposition correspond to elements of theproblem description, then the decompositionmakes a good domain model.

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 101

Page 102: Information Hiding - University of Waterloo · Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, “On the criteria to be used in decomposing

Why this Topic? -6

That’s why I teach Parnas’s method in arequirements engineering course!

1996 Daniel M. Berry Software Enginering Information Hiding Pg. 102


Recommended