Nama: Christian Gunawan
NIM: 1801384174
Kali ini saya akan menjawab Assignment #11 dari Chapter 11 Programming Language Concepts R Sebesta :
Review Questions #6-10 :
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?
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?
Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more). 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 use of Ada with clause is to make the names defined in external packages visible.
Problem Set #6-10 :
6. Discuss the advantages of C# properties, relative to writing accessor methods in C++ or Java.
One of the advantage of C# properties relative writing accessor methods in C++ or Java is it can control access to the fields.
7. Explain the dangers of C’s approach to encapsulation.
The main problem is that the biggest part of encapsulation is done via hidding, rather than protection. This hidding is achieved through definition hidding: 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 appart any "static" method / variable. Static is actually the only rue level of protection here, as it's the only one that another unit (file) would not be able to access even if it's aware of it's existence. This whole "protection-is-name-hiding" approach leads to a load of problems: you can access a symbol using the wrong datatype and your compiler will happily do so. To protect critical parts, you should rely on text being hidden from the compiler while it's processing certain units (via #ifdef / #define).
8. Why didn’t C++ eliminate the problems discussed in Problem 7?
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. 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. So sometimes methods call in C++ can be more or less readable than those of Objective-C.
No comments:
Post a Comment