PLC : SESSION 8 (Abstract Data Type) (GSLC)

In this session, we have GSLC class so Ms.Yanfi only gave us some questions through the Binusmaya Forum and gave us about a week to answer it through the forum.

 

Here is the question:

  1. What are the similarities of and the differences between Java Packages and C++ Namespace?
  2. Explain the dangers of C’s approach to encapsulation.

 

And here are the answers I wrote on the forum:

  1. The similarities:

– Java packages are namespace system while C++ also has namespace

– Both are abstract containers for classes

– Java packages and namespaces both provide breakup for class names

– Both make the code cleaner and less redundant, by enabling some parts of the                        code

 

The Differences:

– Java’s packages are a namespace system

– In C++ namespaces are just about partitioning the available names.

– Java packages are about modules

 

  1. The main problem is that the biggest part of encapsulation is done via hiding, rather than protection. This is achieved through definition hiding: a header file is preprocessed (which is a synonym for copy-pasted) into the implementation file. Anyone with this header file will be able to access any method or public variable of a the client related to the header, left apart any “static” method / variable. 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.
This entry was posted in Programming Language Concept. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *