Session 8 : Abstract Data Types(GSLC)

here is some task from ms.Yanfi because of GSLC

1. What are the similarities of and the differences between Java Packages and C++ Namespace? 
The similarity between Java Package and Namespaces In C++ are : 
- Java Packages are namespaces system while C++ also has namespace 
- Both are abstract containers for classes 
- Java Packages and namespaces provide breakup for class names 
- both make the code cleaner and less redundant, by enabling some 
parts of the code 
The differences between C++ namespace and Java packages : 
- As a unit that guarantees access to non-private members to classes in the same block, there is no equivalent in C++ that the access level granted to a class is independent of the namespace where the class is defined. 
- In C++ namespaces are just about partitioning the available names. Java packages are about modules. 
- Packages are used to organize files or public types to avoid type conflicts. 
- As a way of ordering your sources in the disk, there is no equivalent that the C++ language has no requirements on how the code is stored in files. 
- They do not enforce any physical file hierarchy like Java packages do 
2. Explain the dangers of C's approach to encapsulation. 
The danger of C's encapsulation is caused by 2 problems, there are : 
- the documentation of the dependence of the client program on the library (and its header file) is lost. 
- the author of the library could change the header file and the implementation file, but the client could attempt to use the new implementation file (not realizing it had changed) but with the old header file, which the user had copied into his or her client program.

Komentar