Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Modules and encapsulation
1. Modules and encapsulation
2. Modules and encapsulation
As programs became larger, it became more important to be able to share libraries of code.
There are various ways to share code.
Older languages such as Fortran had ways to create code libraries.
3. Modules and name spaces
A module or namespace is a way to encapsulate data and code.
The interface is how code interacts with the data and code.
The implementation is the data and code that is otherwise hidden from the outside.
4. API
An
API (
Application Program Interface) is a way to interact with code.
The API is the interface to the underlying data and code.
In 2019, the United States Supreme Court agreed to hear a case of Google vs. Oracle whereby Oracle claims that the Java API is protected under copyright law - which to date has not been the case.
5. C
The C programming language introduced a simple way to share code.
The interface is in a .h header file, which included global constants, variables, and function interfaces - called prototypes.
The implementation is in a .c code file.
6. Drawbacks
The drawbacks of this approach include the following.
All constants, variables, function prototypes/signatures, etc., are global. There is no namespace concept.
Whenever a function prototype/signature is changed, it needs to be changed in two places - a copy-update issue.
7. Java
Java has no name spaces as such. Instead, classes are used to encapsulate namespaces.
This can make Java somewhat tedious to use as all classes need to be in a separate file.
Some languages, such as C#, have namespaces whereby multiple related classes can reside in the same file.
8. End of page
9. Acronyms and/or initialisms for this page
1 acronyms omitted (login required)