/* This is an example of the FUNCTIONAL+ STYLE of design. Several features are to be noted: (a) Physical modules: 3 file file1 = application (client): vectorapp.c file2 = vector abstraction interface: vector.h file3 = vector abstraction implementation: vector.c (b) Logical modules: 16 functions - client application: main() - vector abstraction; 2 exported typedefs and 15 methods new methods were added for Polar and Cartesian views together with methods for IO (c) Language supported data abstractions used: file. (d) Application defined data abstractions: Vector. (e) Data encapsulation used: YES The type Vector IS now encapsulated in its own physical modules (vector.h and vector.c). (f) Information hiding used: Limited, but more than MONOLITHIC. In reference to type Vector we note the following: - The representation of the type is still visible and accessable to the client code. However, without studying the Vector methods, it is not obvious what internal view the Vector abstraction is using. While this was also true in the MONOLITHIC style, the use of data encapsulation has made it much more difficult to discover the internal view. The Vector interface supports both logical views of vectors via the view-specific methods, so the client can take whatever external view it wishes and thus does not really need to know the internal view used to implement the Vector abstration. - The client no longer explicitly references and accesses the internal components of type Vector (x,y). The parsing of vectors on input is provided by special input methods, Getpolar() and Getcart(). Consequently, the external format or syntax of vectors on input streams is completely encapsulated in the Vector abstraction and hidden from the client - the client simply does not need to know this format. - In general, information hiding is almost complete in this style. It is not perfect because the C language does not prevent malicious or accidental access to the internal representation of Vector instances. With sufficient effort, clients of the Vector abstraction can still by- pass any of the Vector methods defined by the interface. SO, complete information hiding is only possible with language support. To improve our design, we must therefore use languages (C++, Java, or Ada95) that enforce information hiding. (g) Decomposition stype: FUNCTIONAL with Data Abstraction (h) Degree of OO'ness: - Variables are used to denote File objects. The C language provides various library functions (methods) for manipulating file objects. Furthermore, the internal representation of file objects is effectively hidden from all client code. The fopen() function is a constructor for file objects. The fclose() function is a destructor for file objects. - Within a single instance of a "problem," Vector variables are used consistent with an object view; that is, variables always denote the same Vector instance - this is a virtue of the client code, not a virtue of the C language. Operations on Vectors are consistent with an object view. There is a subtle difference between this style and the MONOLITHIC. All variables denoting Vector instances are pointers to Vectors. Thus the client references all Vector instances in a uniform way - this is in contrast to the MONOLITHIC style. There is one other difference. Observe that the declarations of Vector variables have been moved from outside the while-loop to inside the while loop. What are the implications of this change? Is this an improvement or not??? Hint: storage for local variables declared in a block statement is automatically deallocated when the block terminates - will this destroy the Vector objects referenced by the Vector variables?? Are memory leaks possible?? 87 */