nav

       HOME    BINUS EVENT   HOW TO   KBP   THOUGHTS

About



Friday, January 16, 2015

Assignment #11

Source:
Concepts of Programming Languages, Robert W. Sebesta.
Chapter 11: Abstract Data Types and Encapsulation Constructs, page 519-521

By:
Name : Helena Natanael
NIM  : 1801380333




Review Question:

6. Explain how information hiding is provided in an Ada package.
There are two approaches to hiding the representation from clients in the package specification. The first one is to include two sections in the package specification, the second one is in which entities are visible to clients and one that hides its contents.

7. To what is the private part of an Ada package specification visible?
The private part of an Ada package specification is visible to the compiler but not to the client programs.

8. What is the difference between private and limited private types in Ada?
Private types have built-in operations for assignment and comparison. Limited private types don’t have built-in operations.

9. What is in an Ada package specification? What about a body package?
Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.

10. What is the use of the Ada with clause?

The ‘with’ clause in Ada makes the names defined in external packages visible.



Problem Sets:

6. Discuss the advantages of C# properties, relative to writing accessor methods in C++ or Java.
The advantage of C# Properties relative to writing accessor are:
- Read-only access can be provided, by having a getter method but no corresponding setter method.
- Constraints can be included in setters. For example, if the data value should be restricted to a particular range, the setter can enforce that.
- The actual implementation of the data member can be changed without affecting the clients if getters and setters are the only access.

7. Explain the dangers of C’s approach to encapsulation.
There are two problems with this approach. First, the documentation of the dependence of the client program on the library (and its header file) is lost. Second, 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.

8. Why didn’t C++ eliminate the problems discussed in Problem 7? 
Because in C++ these kinds of problems can be handled by allowing nonmember functions to be “friends” of a class. Friend functions have access to the private entities of the class where they are declared to be friends.

9. What are the advantages and disadvantages of the Objective-C approach to syntactically distinguishing class methods from instance methods?
Instance methods use an instance of a class, whereas a class method can be used with just the class name. A class is like the blueprint of a house: You only have one blueprint and (usually) you can't do that much with the blueprint alone. An instance (or an object) is the actual house that you build based on the blueprint: You can build lots of houses from the same blueprint. You can then paint the walls a different color in each of the houses, just as you can independently change the properties of each instance of a class without affecting the other instances.

10. In what ways are the method calls in C++ more or less readable than
those of Objective-C?
In Objective C, all method calls are essentially virtual. This makes it a bit easier on the programmer, but it comes at a possible performance decrease. Hence sometimes methods call in C++ can be more or less readable than those of Objective-C.

No comments:

Post a Comment