CS 342 Lecture -*- Outline -*- * Information hiding ** Why share data? Database of nearest stars -subroutines: INSERT, GETDIS, GETBRI, GETRA, GETDECL -d.s.: array of NAMES, 2 arrays of coordinates (RA, DECL), and arrays DISTAN, BRTNSS -have to declare arrays in main program and pass them to all clients --------------- CALL INSERT(NM,R,D,FAR,BRI, NAMES,RA,DECL,DISTAN,BRTNSS) -------------- Costs: details spread throughout program so high maintenance costs (to add more arrays, have to modify entire program) (to change from Km to light-years, have to check whole program) also: security, efficiency ** Information hiding principle (Parnas) design modules so that 1. users have information needed to use module, nothing more 2. implementor has information needed to implement, nothing more (prevent unintended access, modification, observation of data) ** COMMON blocks allow subroutines (operations on DB) to share private data *** included in each subprogram -each subprogram can name the parts differently *** notation is positional *** stars database example ------------------- Database of stars User interface: -subroutines: INSERT, GETDIS, GETBRI, GETRA, GETDECL Data structures: -arrays: NAMES, RA, DECL, DISTAN, BRTNSS declaring arrays in main program NAMES(100),RA(100),DECL(100),DISTAN(100),BRTNSS(100) and passing to all clients: CALL INSERT(NM,R,D,FAR,BRI, NAMES,RA,DECL,DISTAN,BRTNSS) using a COMMON block COMMON /STARS/ NAMES(100),RA(100),DECL(100),DISTAN(100),BRTNSS(100) and sparing clients the details: CALL INSERT(NM,R,D,FAR,BRI) ----------------------- *** mistakes cause problems (aliases) -accidental typing mistakes (e.g., reverse fields) will cause miscommunication problems -mistakes can also circumvent type system COMMON /B/ X,Y(100),I vs. COMMON /B/ X,Y(10),I will alias I and Y(11), so can treat same location as both an integer and a real