Wednesday, June 26, 2013

Concepts of Programming Languages ---- Chapter 12 Support for Object-Oriented Programming

Concepts of Programming Languages ---- Chapter 12 Support for Object-Oriented Programming

Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 12 Support for Object-Oriented Programming



Review Question
2.   Define abstract data type.
An abstract data type is a data structure that are representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition.
6 .  Explain how information hiding is provided in Ada package.
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.   What is dynamic dispatch?
Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions.
8.   What is an abstract method? What is an abstract class?
An abstract method is an implemented method which all of descendant class should have and it is included in Building. An abstract class is  a class that includes at least one abstract method.
11. What is the message protocol of an object?
The message protocol of an objects are all the methods.
12. From where are Smalltalk objects allocated?
Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced.
18. From where can C++ objects be allocated?
The objects of C++ can be static, stack dynamic, or heap dynamic. Explicit deallocation using the delete operator is required for heap-dynamic objects, because C++ does not include implicit storage reclamation.
19. How are C++ heap-allocated objects deallocated?
C++ heap-allocated objects are deallocated using destructor.
31. What is the root class in Objective-C?
The predefined root class named NS Object
33. What is the purpose of an Objective-C category?
The purpose of an Objective-C category is to add certain functionalities to different classes and also to provide some of the benefits of multiple inheritance, without the naming collisions that could occur if modules did not require module names on their functions.
38. What is boxing?
Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value’s type.
39. How are Java objects deallocated?
By implicitly calling a finalize method when the garbage collector is about to reclaim the storage occupied by the object.

Problem Set
1 .  What important part of support for inheritance is missing in Java?
Java does not support the private and protected derivations of C++. One can surmise that the Java designers believed that subclasses should be subtypes, which they are not when private and protected derivations are supported. Thus, they did not include them.
2.   In what ways can “compatible “ be defined for the relationship between an overridden method and the overriding method?
Every overriding method must have the same number of parameters as the overridden method and the types of the parameters and the return type must be compatible with those of the parent class.
7.   What is one programming situation where multiple inheritance has a significant disadvantage over interfaces?
A situation when there are two classes derived from a common parent and those two derived class has one child.
10. Explain one advantage of inheritance.
One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common  code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be  refactored to move the common code up to a mutual super class. This also tends to result in a better organization of  code and smaller, simpler compilation units.
12. Compare inheritance and nested classes in C++. Which of these supports an is-a relationship?
Inheritance is where one class (child class) inherits the members of another class (parent class). Nested class is a class declared entirely within the body of another class or interface.
Inheritance does.
13. Describe the mechanism of dynamic dispatch with an example in Java. Is it possible to dynamically dispatch the data members?
In C++, a method must be defined as virtual to allow dynamic binding. In Java, all method calls are dynamically bound unless the called method has been defined as final, in which case it cannot be overridden and all bindings are static. Static binding is also used if the method is static or private, both of which disallow overriding.
17. What are the different options for object destruction in Java?
is no explicit deallocation operator. A finalize method is implicitly called when the garbage collector  about to reclaim the storage occupied by the object.
20. Compare the way Smalltalk provides dynamic binding with that of C++
In C++, the programmer can specify whether static binding or dynamic binding is to be used. Because static binding is faster, this is an advantage for those situations where dynamic binding is not necessary. Furthermore, even the dynamic binding in C++ is fast when compared with that of Smalltalk. Binding a virtual member function call in C++ to a function definition has a fixed cost, regardless of how distant in the inheritance hierarchy the definition appears. Calls to virtual functions require only five more memory references than statically bound calls (Stroustrup, 1988). In Smalltalk, however, messages are always dynamically bound to methods, and the farther away in the inheritance hierarchy the correct method is, the longer it takes. The disadvantage of allowing the user to decide which bindings are static and which are dynamic is that the original design must include these decisions, which may have to be changed later.
25. Study and explain private and public modifiers in C++. How do those modifiers differ in C#?
      C++ includes both classes and structs, which are nearly identical constructs. The only difference is
      that the default access modifier for class is private, whereas for structs it is public. C# also has structs,
      but they are very different from those of C++. In C#, structs are, in a sense, lightweight classes. They
      can have constructors, properties, methods, and data fields and can implement interfaces but do not
      support inheritance.

No comments:

Post a Comment