Tuesday, January 13, 2015

Q&A Assignment #13 Chapter 11 Review Questions & Problem Set

Name : Vina Melinda
NIM  : 1801380106

Untuk kali ini saya akan menjawab Assignment #13 Problem Set dan Review Questions dari Chapter 11 dari Sebesta.


Review Question:


6. Q: Explain how information hiding is provided in an Ada package.
A: Data type representations can appear in the package specification but be hidden from clients by putting them in the private clause of the package. The abstract type itself is defined to be private in the public part of the package specification. Private types have built-in operations for assignment and comparison for equality and inequality.

7. Q: To what is the private part of an Ada package specification visible?
A:  The representation of the type appears in a part of the specification called the private part, which is introduced by the reserved word private. The private clause is always at the end of the package specification. The private clause is visible to the compiler but not to client program units.

8. Q: What is the difference between private and limited private types
in Ada?
A: Types that are declared to be private are called private types. Private data types have built-in operations for assignment and comparisons for equality and inequality. Any other operation must be declared in the package specification. An alternative to private types is a more restricted form: limited private types. Nonpointer limited private types are described in the private section of a package specification, as are nonpointer private types. The only syntactic difference is that limited private types are declared to be limited private in the visible part of the package specification. that defined the type.

9. Q: What is in an Ada package specification? What about a body package?
A: The encapsulating constructs in Ada are called packages. A package can have two parts, each of which is also is called a package. These are called the package specification, which provides the interface of the encapsulation (and perhaps more), and the body package, which provides the implementation of most, if not all, of the entities named in the associated package specification.


10. Q: What is the use of the Ada with clause?
A: The with clause makes the names defined in external packages visible; in this case Ada.Text_IO, which provides functions for input and output of text.



Problem Set:


6. Q: Discuss the advantages of C# properties, relative to writing accessor
methods in C++ or Java.
A: One of the advantages of C# properties relative writing accessor methods in C++ or Java is it can control access to the fields

7. Q: Explain the dangers of C’s approach to encapsulation.
A: 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.

8. Q: Why didn’t C++ eliminate the problems discussed in Problem 7?
A: Because in C++ these 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. However, it didn't eliminate the problem because it evolved from C. Hence, it kept a lot of backward compatibility, and the same way of doing basic things. While some problems where solved (like the protected access, which is in-between normal and static in C), some stay, as the symbol access using wrong datatype (inherent to the linker, which doesn't do type-checking).

9. Q: What are the advantages and disadvantages of the Objective-C approach to syntactically distinguishing class methods from instance methods?
A: 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. Q: In what ways are the method calls in C++ more or less readable than
those of Objective-C?
A: 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