Information Hiding
Total Page:16
File Type:pdf, Size:1020Kb
Information Hiding Daniel M. Berry 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 1 Information Hiding -1 The concept of information hiding (IH) comes from the seminal paper, ªOn the criteria to be used in decomposing systems into modulesº, CACM, Dec., 1972 by David L. Parnas. The purpose of information hiding is to obtain a modularization of the code of a system that isolates changes into single modules. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 2 Information Hiding -2 Information hiding is a way to use abstract data types and abstract objects, such as provided by g Ada packages g Simula classes g 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 ADT&O -1 It is necessary to teach exploitation of abstract data types and objects (ADT&O). I have found many people writing FORTRAN code in Ada syntax or C code in C++ syntax. On the other hand, it is possible to exploit ADT&O even in assembly language and FORTRAN! 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 4 ADT&O -2 What's a nice programming topic like you doing in a real rough requirements engineering course like this? g ADT&O is a good way to organize a domain model g ADT&O is a good way to organize a software design 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 5 ADT&O -3 Remember that you may have to do some design to discover all requirements. With ADT&O, the domain model and design can be built without exposing implementation details! 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 6 ADT&O -4 In my experience, if I program with ADT&O using information hiding, my modules end up being the types and objects of the domain model. So even if I am thinking implementation, I end up with a domain model! 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 7 ADT&O and IH -1 For those of you who are implementation- bound in your thinking, ADT&O with information hiding frees you from thinking implementation. ADT&O with IH gives you a way of thinking at an abstract level without having to worry about whether you can implement, because you can! 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 8 ADT&O and IH -2 You will see an entirely different way of thinking about problems, in which you work with problem-level concepts rather than more traditional data- or control-¯ow concepts. If you're already thinking this way, bravo! If not, then learn! 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 9 Parnas's Sample Problem Requirements: The KWIC index system accepts an ordered set [sic] of lines, each line is an ordered set [sic] of words, and each word is an ordered set [sic] of characters. Any line may be ªcircularly shiftedº by repeatedly removing the ®rst word and appending it at the end of the line. The KWIC index system outputs a listing of all the circular shifts of all lines in alphabetical order. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 10 List of Six Lines Make - A Program for Maintaining Computer Programs Reference Manual for the Ada Programming Language The NYU Ada/Ed System, An Overview Program Design Language Software Development Processor User Reference Manual The Ina Jo Reference Manual The next slide shows the KWIC (KeyWord In Context) index of the above lines. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 11 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 KWIC Index of Above Lines First 5 lines of Index: c Make c - A Program for Maintaining Computer Programs [Fel78] Make - c A Program for Maintaining Computer Programs [Fel78] Reference Manual for the c Ada Programming language [Ada81] c The NYU c Ada/ed System, An Overview [NYU81] The NYU Ada/ed System, c An Overview [NYU81] 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 13 Two Modularizations Parnas shows ®rst a conventional modularization and then one that does a better job of being modi®able. Modularization 1: Brand X Modularization 2: Brand DLP Guess which one is supposed to be better! The textual module descriptions are from Parnas himself. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 14 Modularization 1 -1 BRAND X: Modularization 1 KWIC circular_ input alphabetizer output shifter 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 15 Modularization 1 -2 DATA STRUCTURE DIAGRAM words 1 11 2 1 51 3 1 2 4 1 103 5 2 97 6 2 18 7 2 54 line_index cs_line_index alphed_cs_line_index 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 16 Modularization 1 -3 Module 1: Input. This module reads the data lines from the input medium and stores them in core for processing by the remaining modules. The characters are packed four to a word, and an otherwise unused character is used to indicate the end of a word. An index is kept to show the start of each line. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 17 Modularization 1 -4 Module 2: Circular Shift. This module is called after the input module has completed its work. It prepares an index which gives the address of the ®rst character of each circular shift, and the original index of the line in the array made up by module 1. It leaves its output in core with words in pairs (original line number, starting address). 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 18 Modularization 1 -5 Module 3: Alphabetizing. This module takes as input the arrays produced by modules 1 and 2. It produces an array in the same format as that produced by module 2. In this case, however, the circular shifts are listed in another order (alphabetically). 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 19 Modularization 1 -6 Module 4: Output. Using the arrays produced by module 3 and module 1, this module produces a nicely formatted output listing of all of the circular shifts. In a sophisticated system the actual start of each line will be marked, pointers to further information may be inserted, and the start of the circular shift may actually not be the ®rst word in the line, etc. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 20 Modularization 1 -7 Module 5: Master Control. This module does little more than control the sequencing among the other four modules. It may also handle error messages, space allocation, etc. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 21 Modularization 1 -8 Parnas says: It should be clear that the above does not constitute a de®nitive document. Much more information would have to be supplied before work could start. The de®ning documents would include a number of pictures [as above] showing core formats, pointer conventions, calling conventions, etc. All of the interfaces between the four modules must be speci®ed before work could begin. 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 22 Modularization 1 -9 I add the additional de®ning documents using Ada notation: procedure KWIC is type 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 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 Modularization 1 -11 begin input; make_circular_shifts; alphabetize; output; end KWIC; 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 25 Modularization 1 -12 separate(KWIC) procedure input is begin null; end; separate(KWIC) procedure make_circular_shifts is begin null; end; 1996 Daniel M. Berry Software Enginering Information Hiding Pg. 26 Modularization 1 -13 separate(KWIC) procedure alphabetize is begin null; end; separate(KWIC) procedure output is begin null; end; 1996 Daniel M.